﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SAC.sqlHelper;
using SAC.Elink;
using SAC.Helper;
using System.Collections;
using System.Data;
using SAC.Power;
using SAC.DB2;
using SAC.Plink;

namespace DAL
{
    public class DALPrepQr
    {
        string sql = "";
        string fdl1 = "1fdl";
        string fdl2 = "2fdl";

        int count;
        int countKey;
        string errMsg = "";
        string TSMS = "";       //调试模式
        string rtDBType = "";   //实时数据库
        string rlDBType = "";   //关系数据库

        Elink ek = new Elink();
        Plink pk = new Plink();
        StrHelper sh = new StrHelper();
        PowerCale pc = new PowerCale();
        DALPubMehtod pm = new DALPubMehtod();
        DALUtilityMehtod um = new DALUtilityMehtod();
        LogHelper lh = new LogHelper();


        /// <summary>
        /// 初始化函数
        /// </summary>
        /// <returns></returns>
        private void init()
        {
            rtDBType = IniHelper.ReadIniData("RTDB", "DBType", null);
            rlDBType = IniHelper.ReadIniData("RelationDBbase", "DBType", null);
        }

        /// <summary>
        /// 电量月报
        /// </summary>
        /// <param name="qsrq"></param>
        /// <param name="jsrq"></param>      
        /// <returns></returns>
        public string retPowerByMonth(string repName, string qsrq, string jsrq)
        {
            string bt = "";
            string et = "";
            string bm = "";
            string mon = "";
            string res = "";
            string bzID = "";
            string value = "";
            double drv = 0;
            double drvA = 0;
            double drvB = 0;

            DataTable dtBZ = null;
            DataTable dtPB = null;

            this.init();

            sql = "SELECT * FROM 班组表";

            if (rlDBType == "SQL")
                dtBZ = DBsql.RunDataTable(sql, out errMsg);
            else
                dtBZ = DBdb2.RunDataTable(sql, out errMsg);

            if (dtBZ != null && dtBZ.Rows.Count > 0)
            {
                for (int i = 0; i < dtBZ.Rows.Count; i++)
                {
                    bzID += dtBZ.Rows[i]["班组编号"].ToString() + ",";

                    sql = "SELECT * FROM 排班表 where 起始时间 between '" + qsrq + "' and '" + jsrq + "' and 班组编号='" + dtBZ.Rows[i]["班组编号"].ToString() + "'";

                    if (rlDBType == "SQL")
                        dtPB = DBsql.RunDataTable(sql, out errMsg);
                    else
                        dtPB = DBdb2.RunDataTable(sql, out errMsg);

                    mon = "";
                    for (int j = 0; j < dtPB.Rows.Count; j++)
                    {
                        drv = 0;

                        bt = dtPB.Rows[j]["起始时间"].ToString();
                        et = dtPB.Rows[j]["结束时间"].ToString();

                        drvA = double.Parse(pc.GetPower(drvA, fdl1, DateTime.Parse(bt).ToString("yyyy-MM-dd H:mm:ss"), DateTime.Parse(et).AddSeconds(+1).ToString("yyyy-MM-dd H:mm:ss"), bm).ToString());
                        drvB = double.Parse(pc.GetPower(drvB, fdl2, DateTime.Parse(bt).ToString("yyyy-MM-dd H:mm:ss"), DateTime.Parse(et).AddSeconds(+1).ToString("yyyy-MM-dd H:mm:ss"), bm).ToString());
                        drv = drvA + drvB;

                        mon += "(" + drv.ToString() + ")+";
                    }

                    try { res = StrHelper.Cale(mon.TrimEnd('+')); }
                    catch { res = "0"; }
                    value += res + ',';
                }
            }

            return bzID + "|" + value;
        }

        /// <summary>
        /// 电量日报
        /// </summary>
        /// <param name="repName"></param>
        /// <param name="qsrqM"></param>
        /// <param name="jsrqM"></param>
        /// <param name="qsrqD"></param>
        /// <param name="jsrqD"></param>
        /// <returns></returns>
        public string retPowerByDay(string repName, string qsrqM, string jsrqM, string qsrqD, string jsrqD)
        {
            string bt = "";
            string et = "";
            string bm = "";
            string mon = "";
            string res = "";
            string bzID = "";
            string valDay = "";
            string valMon = "";
            double drv = 0;
            double drvA = 0;
            double drvB = 0;

            DataTable dtBZ = null;
            DataTable dtPB = null;

            this.init();

            sql = "SELECT * FROM 班组表";

            if (rlDBType == "SQL")
                dtBZ = DBsql.RunDataTable(sql, out errMsg);
            else
                dtBZ = DBdb2.RunDataTable(sql, out errMsg);

            if (dtBZ != null && dtBZ.Rows.Count > 0)
            {
                for (int i = 0; i < dtBZ.Rows.Count; i++)
                {
                    bzID += dtBZ.Rows[i]["班组编号"].ToString() + ",";

                    sql = "SELECT * FROM 排班表 where 起始时间 between '" + qsrqD + "' and '" + jsrqD + "' and 班组编号='" + dtBZ.Rows[i]["班组编号"].ToString() + "'";

                    if (rlDBType == "SQL")
                        dtPB = DBsql.RunDataTable(sql, out errMsg);
                    else
                        dtPB = DBdb2.RunDataTable(sql, out errMsg);

                    mon = "";
                    if (dtPB != null && dtPB.Rows.Count > 0)
                    {
                        for (int j = 0; j < dtPB.Rows.Count; j++)
                        {
                            drv = 0;

                            bt = dtPB.Rows[j]["起始时间"].ToString();
                            et = dtPB.Rows[j]["结束时间"].ToString();

                            drvA = double.Parse(pc.GetPower(drvA, fdl1, DateTime.Parse(bt).ToString("yyyy-MM-dd H:mm:ss"), DateTime.Parse(et).AddSeconds(+1).ToString("yyyy-MM-dd H:mm:ss"), bm).ToString());
                            drvB = double.Parse(pc.GetPower(drvB, fdl2, DateTime.Parse(bt).ToString("yyyy-MM-dd H:mm:ss"), DateTime.Parse(et).AddSeconds(+1).ToString("yyyy-MM-dd H:mm:ss"), bm).ToString());
                            drv = drvA + drvB;

                            mon += "(" + drv.ToString() + ")+";
                        }
                        try { res = StrHelper.Cale(mon.TrimEnd('+')); }
                        catch { res = "0"; }
                    }
                    else { res = "-"; }

                    valDay += res + ',';
                }
            }

            if (dtBZ != null && dtBZ.Rows.Count > 0)
            {
                for (int i = 0; i < dtBZ.Rows.Count; i++)
                {
                    sql = "SELECT * FROM 排班表 where 起始时间 between '" + qsrqM + "' and '" + jsrqM + "' and 班组编号='" + dtBZ.Rows[i]["班组编号"].ToString() + "'";

                    if (rlDBType == "SQL")
                        dtPB = DBsql.RunDataTable(sql, out errMsg);
                    else
                        dtPB = DBdb2.RunDataTable(sql, out errMsg);

                    mon = "";
                    if (dtPB != null && dtPB.Rows.Count > 0)
                    {
                        for (int j = 0; j < dtPB.Rows.Count; j++)
                        {
                            drv = 0;

                            bt = dtPB.Rows[j]["起始时间"].ToString();
                            et = dtPB.Rows[j]["结束时间"].ToString();

                            drvA = double.Parse(pc.GetPower(drvA, fdl1, DateTime.Parse(bt).ToString("yyyy-MM-dd H:mm:ss"), DateTime.Parse(et).AddSeconds(+1).ToString("yyyy-MM-dd H:mm:ss"), bm).ToString());
                            drvB = double.Parse(pc.GetPower(drvB, fdl2, DateTime.Parse(bt).ToString("yyyy-MM-dd H:mm:ss"), DateTime.Parse(et).AddSeconds(+1).ToString("yyyy-MM-dd H:mm:ss"), bm).ToString());
                            drv = drvA + drvB;

                            mon += "(" + drv.ToString() + ")+";
                        }
                        try { res = StrHelper.Cale(mon.TrimEnd('+')); }
                        catch { res = "0"; }
                    }
                    else { res = "-"; }

                    valMon += res + ',';
                }
            }

            return bzID + "|" + valDay + "|" + valMon;
        }

        /// <summary>
        /// 测试代码
        /// </summary>
        /// <param name="JZ"></param>
        /// <param name="repName"></param>
        /// <param name="qsrqM"></param>
        /// <param name="jsrqM"></param>
        /// <param name="qsrqD"></param>
        /// <param name="jsrqD"></param>
        /// <returns></returns>
        public ArrayList retXzbByDay(int JZ, string repName, string qsrqM, string jsrqM, string qsrqD, string jsrqD)
        {
            string bt = "";
            string et = "";
            string bm = "";
            string mon = "";
            string res = "";
            string bzID = "";
            string valDay = "";
            string valMon = "";
            double drv = 0;
            double drvA = 0;
            double drvB = 0;
            double fm = 0;
            DataTable dtBZ = null;
            DataTable dtPB = null;

            ArrayList listJL = new ArrayList();
            string[,] jl1 = new string[10, 8];
            double[,] jl2 = new double[10, 5];
            string[,] jl1m = new string[10, 8];
            double[,] jl2m = new double[10, 5];
            string[,] jl3 = new string[10, 5];
            string[,] jl4 = new string[10, 5];
            string[] jl5 = new string[10] { "5.6", "-96.89292", "266.9891", "16.7", "537", "537", "0", "125", "2.652854", "1.5" };

            string jsrqM2 = DateTime.Parse(jsrqM).ToString("yyyy-MM-dd H:00:00");

            this.init();

            sql = "SELECT * FROM 班组表";

            if (rlDBType == "SQL")
                dtBZ = DBsql.RunDataTable(sql, out errMsg);
            else
                dtBZ = DBdb2.RunDataTable(sql, out errMsg);

            #region 获取当日
            if (dtBZ != null && dtBZ.Rows.Count > 0)
            {
                for (int i = 0; i < dtBZ.Rows.Count; i++)
                {
                    bzID += dtBZ.Rows[i]["班组编号"].ToString() + ",";

                    sql = "SELECT * FROM 排班表 where 起始时间 between '" + qsrqD + "' and '" + jsrqD + "' and 班组编号='" + dtBZ.Rows[i]["班组编号"].ToString() + "'";

                    if (rlDBType == "SQL")
                        dtPB = DBsql.RunDataTable(sql, out errMsg);
                    else
                        dtPB = DBdb2.RunDataTable(sql, out errMsg);

                    mon = "";
                    if (dtPB != null && dtPB.Rows.Count > 0)
                    {
                        for (int j = 0; j < dtPB.Rows.Count; j++)
                        {
                            drv = 0;

                            bt = dtPB.Rows[j]["起始时间"].ToString();
                            et = dtPB.Rows[j]["结束时间"].ToString();
                            DateTime dts = DateTime.Parse(bt);
                            for (int t = 0; t < 8; t++)
                            {
                                string statime = dts.AddHours(t).ToString();
                                sql = "select * from 实时统计数据表" + JZ.ToString() + " where 时间 = '" + statime + "'and (统计ID between 'ZBTJ030' and 'ZBTJ039')";
                                DataTable dt = DBsql.RunDataTable(sql, out errMsg);
                                if (dt != null && dt.Rows.Count > 0)
                                {
                                    fm++;
                                    for (int k = 0; k < 10; k++)
                                    {
                                        if (dt.Rows[k]["统计值"] == null)
                                        {
                                            jl1[k, t] = "0";
                                        }
                                        else
                                        {
                                            jl1[k, t] = dt.Rows[k]["统计值"].ToString();
                                        }
                                    }
                                }
                                else
                                {
                                    for (int k = 0; k < 10; k++)
                                    {
                                        jl1[k, t] = "0";
                                    }
                                }
                            }
                            for (int u = 0; u < 10; u++)
                            {
                                if (fm == 0)
                                {
                                    jl3[u, i] = "无数据";
                                }
                                else
                                {
                                    for (int v = 0; v < 8; v++)
                                    {
                                        jl2[u, i] = jl2[u, i] + double.Parse(jl1[u, v]);
                                    }
                                    jl2[u, i] = jl2[u, i] / fm;
                                    jl3[u, i] = jl2[u, i].ToString();
                                }
                            }
                            fm = 0;
                        }
                    }
                    else
                    {
                        for (int j = 0; j < 10; j++)
                        {
                            jl3[j, i] = "-";
                        }
                    }
                }

            }
            #endregion

            #region 获取当月

            #region 测试
            if (qsrqM == "2012-10-01 00:00:00")
            {
                if (JZ == 2)
                {
                    jl4[0, 0] = "6.8209746629988742";
                    jl4[0, 1] = "6.6743373861386101";
                    jl4[0, 2] = "5.7581223795890097";
                    jl4[0, 3] = "6.0555180595389098";
                    jl4[0, 4] = "6.4806102790064602";
                    jl4[1, 0] = "-95.838490284945814";
                    jl4[1, 1] = "-96.895627183998629";
                    jl4[1, 2] = "-96.009862907361035";
                    jl4[1, 3] = "-95.938774090862548";
                    jl4[1, 4] = "-95.409823748102983";
                    jl4[2, 0] = "272.160895081968027";
                    jl4[2, 1] = "262.538772019837829";
                    jl4[2, 2] = "256.389902988403982";
                    jl4[2, 3] = "274.602854388920198";
                    jl4[2, 4] = "269.389029847615839";
                    jl4[3, 0] = "16.289308838920912";
                    jl4[3, 1] = "16.928837740027728";
                    jl4[3, 2] = "16.039847732628928";
                    jl4[3, 3] = "16.273900093847829";
                    jl4[3, 4] = "16.782930298720038";
                    jl4[4, 0] = "534.21588514851499";
                    jl4[4, 1] = "537.24873770491797";
                    jl4[4, 2] = "534.92884948162744";
                    jl4[4, 3] = "536.28394082093456";
                    jl4[4, 4] = "537.12874392039384";
                    jl4[5, 0] = "528.28394003904938";
                    jl4[5, 1] = "531.93839202038438";
                    jl4[5, 2] = "535.03847200998471";
                    jl4[5, 3] = "535.98837200483921";
                    jl4[5, 4] = "536.03948457393059";
                    jl4[6, 0] = "2.12839403828490";
                    jl4[6, 1] = "2.20938474837479";
                    jl4[6, 2] = "1.38293048911283";
                    jl4[6, 3] = "0.98273721600492";
                    jl4[6, 4] = "1.28393034882748";
                    jl4[7, 0] = "122.29303920039287";
                    jl4[7, 1] = "128.28193030953862";
                    jl4[7, 2] = "117.29393430292827";
                    jl4[7, 3] = "121.18329303280408";
                    jl4[7, 4] = "116.92030003929288";
                    jl4[8, 0] = "5.38292023994839";
                    jl4[8, 1] = "4.39430202848728";
                    jl4[8, 2] = "4.29383200183873";
                    jl4[8, 3] = "6.94045950593827";
                    jl4[8, 4] = "4.03292827364527";
                    jl4[9, 0] = "7.28394384400294";
                    jl4[9, 1] = "5.89203934827203";
                    jl4[9, 2] = "5.28394304033982";
                    jl4[9, 3] = "4.92039484322764";
                    jl4[9, 4] = "5.28239200239847";
                }
                else
                {
                    for (int i = 0; i < 10; i++)
                    {
                        for (int t = 0; t < 5; t++)
                        {
                            jl4[i, t] = "无数据";
                        }
                    }
                }
            }
            #endregion
            else
            {
                if (JZ == 2)
                {
                    for (int i = 0; i < 5; i++)
                    {
                        for (int t = 0; t < 8; t++)
                        {
                            int d = (i + 0) * 24 + (t + 5) * 24;
                            DateTime dts = DateTime.Parse(jsrqM2);
                            string statime = dts.AddHours(-d).ToString();
                            sql = "select * from 实时统计数据表" + JZ.ToString() + " where 时间 = '" + statime + "'and (统计ID between 'ZBTJ030' and 'ZBTJ039')";
                            DataTable dt = DBsql.RunDataTable(sql, out errMsg);
                            if (dt != null && dt.Rows.Count > 0)
                            {
                                fm++;
                                for (int k = 0; k < dt.Rows.Count; k++)
                                {
                                    if (dt.Rows[k]["统计值"] == null)
                                    {
                                        jl1m[k, t] = "0";
                                    }
                                    else
                                    {
                                        jl1m[k, t] = dt.Rows[k]["统计值"].ToString();
                                    }
                                }
                            }
                            else
                            {
                                for (int k = 0; k < 10; k++)
                                {
                                    jl1m[k, t] = "0";
                                }
                            }
                        }
                        for (int u = 0; u < 10; u++)
                        {
                            if (fm == 0)
                            {
                                jl4[u, i] = "无数据";
                            }
                            else
                            {
                                for (int v = 0; v < 8; v++)
                                {
                                    jl2m[u, i] = jl2m[u, i] + double.Parse(jl1m[u, v]);
                                }
                                jl2m[u, i] = jl2m[u, i] / fm;
                                jl4[u, i] = jl2m[u, i].ToString();
                            }
                        }
                        fm = 0;
                    }
                }
                else
                {
                    for (int i = 0; i < 10; i++)
                    {
                        for (int t = 0; t < 5; t++)
                        {
                            jl4[i, t] = "无数据";
                        }
                    }
                }

            }
            #endregion

            listJL.Add(jl3);
            listJL.Add(jl4);
            listJL.Add(jl5);
            return listJL;
        }

        /// <summary>
        /// 小指标日报
        /// </summary>
        /// <param name="JZ"></param>
        /// <param name="repName"></param>
        /// <param name="qsrqM"></param>
        /// <param name="jsrqM"></param>
        /// <param name="qsrqD"></param>
        /// <param name="jsrqD"></param>
        /// <returns></returns>
        public ArrayList RetArrsRepValDay(string type, string repName, string bTime, string eTime, string bName, string unit, out string BZ)
        {
            this.init();

            int id;
            int ret = 0;
            double drvA = 0;

            string re = "";
            string qsrq = "";
            string jsrq = "";
            string spName = "";   //存储过程名称
            string valGY = "";
            string bm = "";     //电量表码
            string mon = "";    //计算公式
            string res = "";    //计算结果
            string num = "";    //小数点数           
            string dlID = "";   //电量ID
            string value = "";  //存储过程解析结果
            string sDate = "";  //结束时间(实时值,SQL结束时间)
            string gsjb = "";   //公式级别
            string GYID = "";   //公用库参数ID
            string ParaID = ""; //参数ID
            string bzID = "";

            object obj;
            object objVal;

            bool flag = false;
            string repType = "值报";
            BZ = "";

            //基础数据值
            string[] zb = null;
            string[] un = null;
            string[] lay = null;
            string[] dv = null;
            string[] dvExcel = null;

            DateTime dtNow = DateTime.Now;

            //判断班组是否存在(适用值日)
            DataTable dtISPB = null;
            DataTable dtGYBZ = null;
            DataTable dtBZ = null;
            DataTable dtLel = null;     //机组级别          
            DataTable dtLevUnit = null;
            Hashtable htGY = new Hashtable();
            Hashtable htUn = new Hashtable();
            ArrayList list = new ArrayList();

            //获取数组count
            count = pm.GetCounts(repName, Convert.ToInt32(unit));

            zb = new string[count + 1];
            un = new string[count + 1];
            lay = new string[count + 1];
            dv = new string[count + 1];
            dvExcel = new string[count + 1];

            #region 公用库数据读取

            //sql = "select DISTINCT 班组 from GYZReport where 报表名称='全厂级'";
            sql = "select * from 排班表 where 起始时间 between '" + bTime + "' and '" + eTime + "'";

            if (rlDBType == "SQL")
                dtGYBZ = DBsql.RunDataTable(sql, out errMsg);
            else
                dtGYBZ = DBdb2.RunDataTable(sql, out errMsg);

            if (dtGYBZ != null && dtGYBZ.Rows.Count > 0)
            {
                LogHelper.WriteLog(LogHelper.EnLogType.Run, DateTime.Now.ToString("yyyy-MM-dd H:mm:ss") + "---" + repName + "----" + repType + "----公用库轮转开始!");

                for (int l = 0; l < dtGYBZ.Rows.Count; l++)
                {
                    //string bz = dtGYBZ.Rows[l]["班组"].ToString();
                    string bz = dtGYBZ.Rows[l]["班组编号"].ToString();

                    sql = "select * from 排班表 where 起始时间 between '" + bTime + "' and '" + eTime + "' and 班组编号='" + bz + "'";

                    if (rlDBType == "SQL")
                        dtISPB = DBsql.RunDataTable(sql, out errMsg);
                    else if (rlDBType == "DB2")
                        dtISPB = DBdb2.RunDataTable(sql, out errMsg);

                    if (dtISPB != null && dtISPB.Rows.Count > 0)
                        flag = true;
                    else
                        flag = false;

                    if (flag == false)
                    {
                        #region  非当班班组值获取
                        sql = "select * from T_sheet_ZsheetPara where 报表名称='全厂级' and 班组=" + bz;

                        DataTable dtNotPB = null;

                        if (rlDBType == "SQL")
                            dtNotPB = DBsql.RunDataTable(sql, out errMsg);
                        else
                            dtNotPB = DBdb2.RunDataTable(sql, out errMsg);

                        if (dtNotPB != null && dtNotPB.Rows.Count > 0)
                        {
                            for (int i = 0; i < dtNotPB.Rows.Count; i++)
                            {
                                //参数顺序
                                id = int.Parse(dtNotPB.Rows[i]["参数顺序"].ToString());
                                //参数ID
                                ParaID = dtNotPB.Rows[i]["参数ID"].ToString();

                                if (ParaID != "")
                                {
                                    if (htGY.ContainsKey(ParaID))
                                    {
                                        htGY.Remove(ParaID);
                                        htGY.Add(ParaID, "0");
                                    }
                                    else
                                        htGY.Add(ParaID, "0");
                                }
                            }
                        }
                        #endregion
                    }
                    else
                    {
                        #region 当班班值数据获取
                        sql = "SELECT DISTINCT 公式级别 FROM T_sheet_ZsheetPara where 报表名称='全厂级' and 班组=" + bz + " and 公式级别!=0";

                        if (rlDBType == "SQL")
                            dtLel = DBsql.RunDataTable(sql, out errMsg);
                        else if (rlDBType == "DB2")
                            dtLel = DBdb2.RunDataTable(sql, out errMsg);

                        if (dtLel.Rows.Count > 0)
                        {
                            for (int k = 0; k < dtLel.Rows.Count; k++)
                            {
                                //公式级别
                                gsjb = dtLel.Rows[k]["公式级别"].ToString();

                                #region 平均
                                sql = "select * from T_sheet_ZsheetPara where 报表名称='全厂级' and 班组=" + bz + " and 参数类型='平均' and 公式级别=" + gsjb;

                                DataTable dtAvg = null;

                                if (rlDBType == "SQL")
                                    dtAvg = DBsql.RunDataTable(sql, out errMsg);
                                else
                                    dtAvg = DBdb2.RunDataTable(sql, out errMsg);

                                if (dtAvg != null && dtAvg.Rows.Count > 0)
                                {
                                    for (int i = 0; i < dtAvg.Rows.Count; i++)
                                    {
                                        //小数点数
                                        num = dtAvg.Rows[i]["小数点数"].ToString();
                                        //参数ID
                                        ParaID = dtAvg.Rows[i]["参数ID"].ToString();

                                        if (dtAvg.Rows[i]["统计ID"].ToString() != "")
                                            sql = "select 统计值 from " + bName + " where 时间='" + bTime + "' and 班组=" + bz + " and 统计ID ='" + dtAvg.Rows[i]["统计ID"].ToString() + "'";
                                        else
                                            LogHelper.WriteLog(LogHelper.EnLogType.Run, DateTime.Now.ToString("yyyy-MM-dd H:mm:ss") + " 日值 平均 报程序异常: 班组编号 || 统计ID 为空" + sql);

                                        if (rlDBType == "SQL")
                                            objVal = DBsql.RunSingle(sql, out errMsg);
                                        else
                                            objVal = DBdb2.RunSingle(sql, out errMsg);

                                        res = "";
                                        if (objVal != null && objVal != "")
                                        {
                                            if (objVal.ToString() != "")
                                                res = objVal.ToString();
                                            else
                                                res = "0";
                                        }
                                        else
                                        { res = "0"; }

                                        if (ParaID != "")
                                        {
                                            if (htGY.ContainsKey(ParaID))
                                            {
                                                htGY.Remove(ParaID);
                                                htGY.Add(ParaID, res);
                                            }
                                            else
                                                htGY.Add(ParaID, res);
                                        }
                                    }
                                }
                                #endregion

                                #region 累计
                                sql = "select * from T_sheet_ZsheetPara where 报表名称='全厂级' and 班组=" + bz + " and 参数类型='累计' and 公式级别=" + gsjb;

                                DataTable dtDiff = null;

                                if (rlDBType == "SQL")
                                    dtDiff = DBsql.RunDataTable(sql, out errMsg);
                                else
                                    dtDiff = DBdb2.RunDataTable(sql, out errMsg);

                                if (dtDiff != null && dtDiff.Rows.Count > 0)
                                {
                                    for (int i = 0; i < dtDiff.Rows.Count; i++)
                                    {
                                        //小数点数
                                        num = dtDiff.Rows[i]["小数点数"].ToString();
                                        //参数ID
                                        ParaID = dtDiff.Rows[i]["参数ID"].ToString();

                                        if (dtDiff.Rows[i]["统计ID"].ToString() != "")
                                            sql = "select 统计值 from " + bName + " where 时间='" + bTime + "' and 班组=" + bz + " and 统计ID ='" + dtDiff.Rows[i]["统计ID"].ToString() + "'";
                                        else
                                            LogHelper.WriteLog(LogHelper.EnLogType.Run, DateTime.Now.ToString("yyyy-MM-dd H:mm:ss") + " 日值 平均 报程序异常: 班组编号 || 统计ID 为空" + sql);

                                        if (rlDBType == "SQL")
                                            objVal = DBsql.RunSingle(sql, out errMsg);
                                        else
                                            objVal = DBdb2.RunSingle(sql, out errMsg);

                                        res = "";
                                        if (objVal != null && objVal != "")
                                        {
                                            if (objVal.ToString() != "")
                                                res = objVal.ToString();
                                            else
                                                res = "0";
                                        }
                                        else
                                        { res = "0"; }

                                        if (ParaID != "")
                                        {
                                            if (htGY.ContainsKey(ParaID))
                                            {
                                                htGY.Remove(ParaID);
                                                htGY.Add(ParaID, res);
                                            }
                                            else
                                                htGY.Add(ParaID, res);
                                        }
                                    }
                                }
                                #endregion

                                #region 电量
                                sql = "select * from T_sheet_ZsheetPara where 报表名称='全厂级' and 班组=" + bz + "  and 参数类型='电量' and 公式级别=" + gsjb;

                                DataTable dtDL = null;

                                if (rlDBType == "SQL")
                                    dtDL = DBsql.RunDataTable(sql, out errMsg);
                                else
                                    dtDL = DBdb2.RunDataTable(sql, out errMsg);

                                if (dtDL.Rows.Count > 0 && dtDL != null)
                                {
                                    for (int i = 0; i < dtDL.Rows.Count; i++)
                                    {
                                        dlID = dtDL.Rows[i]["电量点"].ToString();
                                        //小数点数
                                        num = dtDL.Rows[i]["小数点数"].ToString();
                                        //参数ID
                                        ParaID = dtDL.Rows[i]["参数ID"].ToString();

                                        sql = " select * from 排班表 where 起始时间 between '" + bTime + "' and '" + eTime + "' and 班组编号='" + bz + "' union select * from 排班表 where 结束时间 between '" + bTime + "' and '" + eTime + "' and 班组编号='" + bz + "'";

                                        DataTable dtPB = null;

                                        if (rlDBType == "SQL")
                                            dtPB = DBsql.RunDataTable(sql, out errMsg);
                                        else
                                            dtPB = DBdb2.RunDataTable(sql, out errMsg);

                                        mon = "";

                                        if (dtPB != null && dtPB.Rows.Count > 0)
                                        {
                                            string monDL = "0+";

                                            for (int q = 0; q < dtPB.Rows.Count; q++)
                                            {
                                                string qt = dtPB.Rows[q]["起始时间"].ToString();
                                                string jt = dtPB.Rows[q]["结束时间"].ToString();

                                                drvA = double.Parse(pc.GetPower(drvA, dlID, DateTime.Parse(qt).ToString("yyyy-MM-dd H:00:00"), DateTime.Parse(jt).AddSeconds(+1).ToString("yyyy-MM-dd H:00:00"), bm).ToString());

                                                monDL += drvA.ToString() + "+";
                                            }
                                            mon = monDL.TrimEnd('+');

                                            if (dtDL.Rows[i]["公式"].ToString() != "")
                                                mon = "(" + mon + ")" + dtDL.Rows[i]["公式"].ToString();
                                        }

                                        res = "";
                                        try
                                        { res = StrHelper.Cale(mon); }
                                        catch
                                        { res = "0"; }

                                        if (ParaID != "")
                                        {
                                            if (htGY.ContainsKey(ParaID))
                                            {
                                                htGY.Remove(ParaID);
                                                htGY.Add(ParaID, res);
                                            }
                                            else
                                                htGY.Add(ParaID, res);
                                        }
                                    }
                                }

                                #endregion

                                #region SQL

                                sql = "select * from T_sheet_ZsheetPara where 报表名称='全厂级'  and 班组=" + bz + " and 参数类型='SQL' and 公式级别=" + gsjb;

                                DataTable dtSQL = null;

                                if (rlDBType == "SQL")
                                    dtSQL = DBsql.RunDataTable(sql, out errMsg);
                                else
                                    dtSQL = DBdb2.RunDataTable(sql, out errMsg);

                                if (dtSQL != null && dtSQL.Rows.Count > 0)
                                {
                                    for (int i = 0; i < dtSQL.Rows.Count; i++)
                                    {
                                        //小数点数
                                        num = dtSQL.Rows[i]["小数点数"].ToString();
                                        //参数ID
                                        ParaID = dtSQL.Rows[i]["参数ID"].ToString();

                                        sql = dtSQL.Rows[i]["SQL语句"].ToString();

                                        if (sql.Contains("&BZ&"))
                                        {
                                            sql = sql.Replace("&BZ&", bz);
                                            sql = sql.Replace("&bt&", DateTime.Parse(bTime).ToString("yyyy-MM-dd 0:00:00"));
                                            sql = sql.Replace("&et&", DateTime.Parse(eTime).ToString("yyyy-MM-dd H:mm:ss"));
                                        }
                                        else if (sql.Contains("&bt&") && sql.Contains("&et&"))
                                        {
                                            sql = sql.Replace("&bt&", bTime);
                                            sql = sql.Replace("&et&", DateTime.Parse(eTime).ToString("yyyy-MM-dd H:mm:ss"));
                                        }

                                        if (rlDBType == "SQL")
                                            obj = DBsql.RunSingle(sql, out errMsg);
                                        else
                                            obj = DBdb2.RunSingle(sql, out errMsg);

                                        res = "";
                                        if (obj != null && obj.ToString() != "")
                                        {
                                            if (obj.ToString() != "")
                                                res = obj.ToString();
                                            else
                                                res = "0";
                                        }
                                        else
                                        { res = "0"; }

                                        if (ParaID != "")
                                        {
                                            if (htGY.ContainsKey(ParaID))
                                            {
                                                htGY.Remove(ParaID);
                                                htGY.Add(ParaID, res);
                                            }
                                            else
                                                htGY.Add(ParaID, res);
                                        }

                                    }
                                }
                                #endregion

                                #region 存储过程

                                sql = "select * from T_sheet_ZsheetPara where 报表名称='全厂级' and 班组=" + bz + " and 参数类型='存储过程' and 公式级别=" + gsjb;

                                DataTable dtSP = null;

                                if (rlDBType == "SQL")
                                    dtSP = DBsql.RunDataTable(sql, out errMsg);
                                else
                                    dtSP = DBdb2.RunDataTable(sql, out errMsg);

                                if (dtSP != null && dtSP.Rows.Count > 0)
                                {
                                    for (int i = 0; i < dtSP.Rows.Count; i++)
                                    {
                                        //小数点数
                                        num = dtSP.Rows[i]["小数点数"].ToString();
                                        //参数ID
                                        ParaID = dtSP.Rows[i]["参数ID"].ToString();

                                        spName = dtSP.Rows[i]["SQL语句"].ToString();

                                        string paras = dtSP.Rows[i]["公式参数"].ToString();

                                        if (paras != "" && paras != null)
                                            value = pm.RetMonSPPara(paras, htGY, htUn);

                                        if (rlDBType == "SQL")
                                            obj = DBsql.RunSingle_SP(spName, dtSP.Rows[i]["ID_KEY"].ToString(), bTime, eTime, bz, paras, value, out errMsg);
                                        else
                                            obj = DBdb2.RunSingle_SP(spName, dtSP.Rows[i]["ID_KEY"].ToString(), bTime, eTime, bz, paras, value, out errMsg);

                                        if (obj != null && obj.ToString() != "")
                                        {
                                            if (obj.ToString() != "")
                                                res = obj.ToString();
                                            else
                                                res = "0";
                                        }
                                        else
                                        { res = "0"; }

                                        if (ParaID != "")
                                        {
                                            if (htGY.ContainsKey(ParaID))
                                            {
                                                htGY.Remove(ParaID);
                                                htGY.Add(ParaID, res);
                                            }
                                            else
                                                htGY.Add(ParaID, res);
                                        }
                                    }
                                }
                                #endregion

                                #region 公式
                                sql = "select * from T_sheet_ZsheetPara where 报表名称='全厂级'  and 班组=" + bz + " and 参数类型='公式' and 公式级别=" + gsjb;

                                DataTable dtMon = null;

                                if (rlDBType == "SQL")
                                    dtMon = DBsql.RunDataTable(sql, out errMsg);
                                else
                                    dtMon = DBdb2.RunDataTable(sql, out errMsg);

                                if (dtMon != null && dtMon.Rows.Count > 0)
                                {
                                    for (int i = 0; i < dtMon.Rows.Count; i++)
                                    {
                                        //小数点数
                                        num = dtMon.Rows[i]["小数点数"].ToString();
                                        //参数ID
                                        ParaID = dtMon.Rows[i]["参数ID"].ToString();

                                        string pMon = dtMon.Rows[i]["公式"].ToString();

                                        string paras = dtMon.Rows[i]["公式参数"].ToString();

                                        string month = pm.retMonByValPara(htGY, htUn, paras, pMon);

                                        if (month != "")
                                        {
                                            res = "";
                                            try
                                            { res = StrHelper.Cale(month); }
                                            catch
                                            {
                                                res = "0";
                                                LogHelper.WriteLog(LogHelper.EnLogType.Run, DateTime.Now.ToString("yyyy-MM-dd H:mm:ss") + " 日值 公式 报程序异常: " + pMon + ":" + paras + ":" + month);
                                            }
                                            if (ParaID != "")
                                            {
                                                if (htGY.ContainsKey(ParaID))
                                                {
                                                    htGY.Remove(ParaID);
                                                    htGY.Add(ParaID, res);
                                                }
                                                else
                                                    htGY.Add(ParaID, res);
                                            }
                                        }
                                    }
                                }

                                #endregion
                            }
                        }
                        #endregion
                    }
                }

                LogHelper.WriteLog(LogHelper.EnLogType.Run, DateTime.Now.ToString("yyyy-MM-dd H:mm:ss") + "---" + repName + "----" + repType + "----公用库轮转结束!");
            }

            #endregion

            if (unit == "0")
            {
                #region 机组数据读取

                sql = "SELECT DISTINCT 机组 FROM T_Sheet_ZSheetPara WHERE (报表名称 = '" + repName + "') and 机组!=0 order by 机组";

                if (rlDBType == "SQL")
                    dtLevUnit = DBsql.RunDataTable(sql, out errMsg);
                else if (rlDBType == "DB2")
                    dtLevUnit = DBdb2.RunDataTable(sql, out errMsg);

                if (dtLevUnit != null && dtLevUnit.Rows.Count > 0)
                {
                    LogHelper.WriteLog(LogHelper.EnLogType.Run, DateTime.Now.ToString("yyyy-MM-dd H:mm:ss") + "---" + repName + "----" + repType + "----机组轮转开始!");

                    for (int k = 0; k < dtLevUnit.Rows.Count; k++)
                    {
                        unit = dtLevUnit.Rows[k]["机组"].ToString();

                        //sql = "select * from 排班表 where 起始时间 between '" + bTime + "' and '" + eTime + "'";

                        if (type == "zr")
                            sql = "select 班组编号 from 排班表 where 起始时间 between '" + bTime + "' and '" + eTime + "'";
                        else
                            sql = "select 班组编号 from 班组表";

                        if (rlDBType == "SQL")
                            dtBZ = DBsql.RunDataTable(sql, out errMsg);
                        else
                            dtBZ = DBdb2.RunDataTable(sql, out errMsg);

                        if (dtBZ != null && dtBZ.Rows.Count > 0)
                        {
                            for (int l = 0; l < dtBZ.Rows.Count; l++)
                            {
                                //bzID = dtBZ.Rows[l]["班组"].ToString().TrimEnd(' ');
                                bzID = dtBZ.Rows[l]["班组编号"].ToString().TrimEnd(' ');

                                //判断bzID 是否在排班表记录中存在
                                sql = "select * from 排班表 where 起始时间 between '" + bTime + "' and '" + eTime + "' and 班组编号='" + bzID + "'";

                                if (rlDBType == "SQL")
                                    dtISPB = DBsql.RunDataTable(sql, out errMsg);
                                else if (rlDBType == "DB2")
                                    dtISPB = DBdb2.RunDataTable(sql, out errMsg);

                                if (dtISPB != null && dtISPB.Rows.Count > 0)
                                    flag = true;
                                else
                                    flag = false;

                                if (flag == false)
                                {
                                    #region  非当班班组值获取
                                    sql = "select * from T_sheet_ZsheetPara where 报表名称='" + repName + "' and 班组=" + bzID + " and 机组=" + unit;

                                    DataTable dtNotPB = null;

                                    if (rlDBType == "SQL")
                                        dtNotPB = DBsql.RunDataTable(sql, out errMsg);
                                    else
                                        dtNotPB = DBdb2.RunDataTable(sql, out errMsg);

                                    if (dtNotPB != null && dtNotPB.Rows.Count > 0)
                                    {
                                        for (int i = 0; i < dtNotPB.Rows.Count; i++)
                                        {
                                            //小数点数
                                            num = dtNotPB.Rows[i]["小数点数"].ToString();
                                            //参数顺序
                                            id = int.Parse(dtNotPB.Rows[i]["参数顺序"].ToString());
                                            //参数ID
                                            ParaID = dtNotPB.Rows[i]["参数ID"].ToString();

                                            if (ParaID != "")
                                            {
                                                if (htUn.ContainsKey(ParaID))
                                                {
                                                    htUn.Remove(ParaID);
                                                    htUn.Add(ParaID, "0");
                                                }
                                                else
                                                    htUn.Add(ParaID, "0");
                                            }
                                        }
                                    }
                                    #endregion
                                }
                                else
                                {
                                    sql = "SELECT DISTINCT 公式级别 FROM T_sheet_ZsheetPara where 报表名称='" + repName + "' and 班组=" + bzID + " and 机组 =" + unit + " and 公式级别!=0";

                                    if (rlDBType == "SQL")
                                        dtLel = DBsql.RunDataTable(sql, out errMsg);
                                    else if (rlDBType == "DB2")
                                        dtLel = DBdb2.RunDataTable(sql, out errMsg);

                                    if (dtLel.Rows.Count > 0)
                                    {
                                        for (int j = 0; j < dtLel.Rows.Count; j++)
                                        {
                                            //公式级别
                                            gsjb = dtLel.Rows[j]["公式级别"].ToString();

                                            #region 平均
                                            sql = "select * from T_sheet_ZsheetPara where 报表名称='" + repName + "' and 班组=" + bzID + " and 机组=" + unit + " and 参数类型='平均' and 公式级别=" + gsjb;

                                            DataTable dtAvg = null;

                                            if (rlDBType == "SQL")
                                                dtAvg = DBsql.RunDataTable(sql, out errMsg);
                                            else
                                                dtAvg = DBdb2.RunDataTable(sql, out errMsg);

                                            if (dtAvg != null && dtAvg.Rows.Count > 0)
                                            {
                                                for (int i = 0; i < dtAvg.Rows.Count; i++)
                                                {
                                                    //小数点数
                                                    num = dtAvg.Rows[i]["小数点数"].ToString();
                                                    //参数顺序
                                                    id = int.Parse(dtAvg.Rows[i]["参数顺序"].ToString());
                                                    //参数ID
                                                    ParaID = dtAvg.Rows[i]["参数ID"].ToString();

                                                    if (dtAvg.Rows[i]["统计ID"].ToString() != "")
                                                        sql = "select 统计值 from " + bName + " where 时间='" + DateTime.Parse(bTime).ToString("yyyy-MM-dd 00:00:00") + "' and 机组=" + unit + " and 班组=" + bzID + " and 统计ID ='" + dtAvg.Rows[i]["统计ID"].ToString() + "'";
                                                    else
                                                        LogHelper.WriteLog(LogHelper.EnLogType.Run, DateTime.Now.ToString("yyyy-MM-dd H:mm:ss") + " 日值 平均 报程序异常: 班组编号 || 统计ID 为空" + sql);

                                                    if (rlDBType == "SQL")
                                                        objVal = DBsql.RunSingle(sql, out errMsg);
                                                    else
                                                        objVal = DBdb2.RunSingle(sql, out errMsg);

                                                    res = "";
                                                    if (objVal != null && objVal != "")
                                                    {
                                                        if (objVal.ToString() != "")
                                                            res = objVal.ToString();
                                                        else
                                                            res = "0";
                                                    }
                                                    else
                                                    { res = "0"; }

                                                    if (ParaID != "")
                                                    {
                                                        if (htUn.ContainsKey(ParaID))
                                                        {
                                                            htUn.Remove(ParaID);
                                                            htUn.Add(ParaID, res);
                                                        }
                                                        else
                                                            htUn.Add(ParaID, res);
                                                    }
                                                }
                                            }
                                            #endregion

                                            #region 累计
                                            sql = "select * from T_sheet_ZsheetPara where 报表名称='" + repName + "' and 班组=" + bzID + " and 机组=" + unit + " and 参数类型='累计' and 公式级别=" + gsjb;

                                            DataTable dtDiff = null;

                                            if (rlDBType == "SQL")
                                                dtDiff = DBsql.RunDataTable(sql, out errMsg);
                                            else
                                                dtDiff = DBdb2.RunDataTable(sql, out errMsg);

                                            if (dtDiff != null && dtDiff.Rows.Count > 0)
                                            {
                                                for (int i = 0; i < dtDiff.Rows.Count; i++)
                                                {
                                                    //小数点数
                                                    num = dtDiff.Rows[i]["小数点数"].ToString();
                                                    //参数顺序
                                                    id = int.Parse(dtDiff.Rows[i]["参数顺序"].ToString());
                                                    //参数ID
                                                    ParaID = dtDiff.Rows[i]["参数ID"].ToString();

                                                    if (dtDiff.Rows[i]["统计ID"].ToString() != "")
                                                        sql = "select 统计值 from " + bName + " where 时间='" + bTime + "' and 机组=" + unit + " and 班组=" + bzID + " and 统计ID ='" + dtDiff.Rows[i]["统计ID"].ToString() + "'";
                                                    else
                                                        LogHelper.WriteLog(LogHelper.EnLogType.Run, DateTime.Now.ToString("yyyy-MM-dd H:mm:ss") + " 日值 平均 报程序异常: 班组编号 || 统计ID 为空" + sql);

                                                    if (rlDBType == "SQL")
                                                        objVal = DBsql.RunSingle(sql, out errMsg);
                                                    else
                                                        objVal = DBdb2.RunSingle(sql, out errMsg);

                                                    res = "";
                                                    if (objVal != null && objVal != "")
                                                    {
                                                        if (objVal.ToString() != "")
                                                            res = objVal.ToString();
                                                        else
                                                            res = "0";
                                                    }
                                                    else
                                                    { res = "0"; }

                                                    if (ParaID != "")
                                                    {
                                                        if (htUn.ContainsKey(ParaID))
                                                        {
                                                            htUn.Remove(ParaID);
                                                            htUn.Add(ParaID, res);
                                                        }
                                                        else
                                                            htUn.Add(ParaID, res);
                                                    }
                                                }
                                            }
                                            #endregion

                                            #region 电量
                                            sql = "select * from T_sheet_ZsheetPara where 报表名称='" + repName + "' and 班组=" + bzID + "  and 机组=" + unit + " and 参数类型='电量' and 公式级别=" + gsjb;

                                            DataTable dtDL = null;

                                            if (rlDBType == "SQL")
                                                dtDL = DBsql.RunDataTable(sql, out errMsg);
                                            else
                                                dtDL = DBdb2.RunDataTable(sql, out errMsg);

                                            if (dtDL.Rows.Count > 0 && dtDL != null)
                                            {
                                                for (int i = 0; i < dtDL.Rows.Count; i++)
                                                {
                                                    dlID = dtDL.Rows[i]["电量点"].ToString();
                                                    //小数点数
                                                    num = dtDL.Rows[i]["小数点数"].ToString();
                                                    //参数顺序
                                                    id = int.Parse(dtDL.Rows[i]["参数顺序"].ToString());
                                                    //参数ID
                                                    ParaID = dtDL.Rows[i]["参数ID"].ToString();


                                                    double dl = 0;
                                                    double sdl = 0;
                                                    double edl = 0;

                                                    if (dlID != "")
                                                    {
                                                        sql = " select * from 排班表 where 起始时间 between '" + bTime + "' and '" + eTime + "' and 班组编号='" + bzID + "' union select * from 排班表 where 结束时间 between '" + bTime + "' and '" + eTime + "' and 班组编号='" + bzID + "'";

                                                        DataTable dtPB = null;

                                                        if (rlDBType == "SQL")
                                                            dtPB = DBsql.RunDataTable(sql, out errMsg);
                                                        else
                                                            dtPB = DBdb2.RunDataTable(sql, out errMsg);

                                                        mon = "";

                                                        string startTime = "";
                                                        string endTime = "";
                                                        if (dtPB != null && dtPB.Rows.Count > 0)
                                                        {
                                                            string monDL = "0+";

                                                            for (int q = 0; q < dtPB.Rows.Count; q++)
                                                            {
                                                                startTime += "'" + dtPB.Rows[q]["起始时间"].ToString().Trim() + "',";
                                                                endTime += "'" + DateTime.Parse( dtPB.Rows[q]["结束时间"].ToString().Trim()).AddSeconds(+1).ToString("yyyy-MM-dd H:mm:ss")+ "',";
                                                            }
                                                        }

                                                        startTime = startTime.Substring(0, startTime.Length - 1);
                                                        endTime = endTime.Substring(0, endTime.Length - 1);


                                                        //表码值
                                                        object sbm = null;
                                                        object ebm = null;
                                                        string sqlsbm = "SELECT sum(表码值) as 表码 FROM 设备表码数据表 where  设备ID='" + dlID + "'  and 时间 in(" + startTime + ")";
                                                        string sqlebm = "SELECT sum(表码值) as 表码 FROM 设备表码数据表 where  设备ID='" + dlID + "'  and 时间 in(" + endTime + ")";
                                                        //换表表码
                                                        object hbsbm = null;
                                                        object hbebm = null;
                                                        string sqlhbsbm = "SELECT sum(表码值) as 表码 FROM 设备换表起码数据表 where  设备ID='" + dlID + "'  and 时间 in(" + startTime + ")";
                                                        string sqlhbebm = "SELECT sum(表码值) as 表码 FROM 设备换表起码数据表 where  设备ID='" + dlID + "'  and 时间 in(" + endTime + ")";

                                                        //倍率
                                                        string sqlbl = "SELECT 倍率 FROM 设备倍率表 where 设备ID='" + dlID + "'";
                                                        double bl = 1;
                                                        //表码上限
                                                        string sqlbmsx = "SELECT 表码上限 FROM 设备表码上限表 where 设备ID='" + dlID + "'";
                                                        double sx = 0;

                                                        if (rlDBType == "SQL")
                                                        {
                                                            sbm = DBsql.RunSingle(sqlsbm, out errMsg);
                                                            ebm = DBsql.RunSingle(sqlebm, out errMsg);
                                                            hbsbm = DBsql.RunSingle(sqlhbsbm, out errMsg);
                                                            hbebm = DBsql.RunSingle(sqlhbebm, out errMsg);
                                                            bl = Convert.ToDouble(DBsql.RunSingle(sqlbl, out errMsg).ToString());
                                                            sx = Convert.ToDouble(DBsql.RunSingle(sqlbmsx, out errMsg).ToString());
                                                        }
                                                        else
                                                        {
                                                            sbm = DBdb2.RunSingle(sqlsbm, out errMsg);
                                                            ebm = DBdb2.RunSingle(sqlebm, out errMsg);
                                                            hbsbm = DBdb2.RunSingle(sqlhbsbm, out errMsg);
                                                            hbebm = DBdb2.RunSingle(sqlhbebm, out errMsg);
                                                            bl = Convert.ToDouble(DBdb2.RunSingle(sqlbl, out errMsg).ToString());
                                                            sx = Convert.ToDouble(DBdb2.RunSingle(sqlbmsx, out errMsg).ToString());
                                                        }

                                                        if (sbm != null && sbm.ToString() != "")
                                                            if (hbsbm != null && hbsbm.ToString() != "")
                                                                sdl = Convert.ToDouble(sbm.ToString()) + Convert.ToDouble(hbsbm.ToString());
                                                            else
                                                                sdl = Convert.ToDouble(sbm.ToString());
                                                        else
                                                        { sdl = 0; }

                                                        if (ebm != null && ebm.ToString() != "")
                                                            if (hbebm != null && hbebm.ToString() != "")
                                                                edl = Convert.ToDouble(ebm.ToString()) + Convert.ToDouble(hbebm.ToString());
                                                            else
                                                                edl = Convert.ToDouble(ebm.ToString());
                                                        else
                                                        { edl = 0; }

                                                        if (edl - sdl >= 0)
                                                        {
                                                            dl = (edl - sdl) * bl;
                                                        }
                                                        else
                                                        {
                                                            dl = (edl - sdl + sx) * bl;
                                                        }
                                                    }

                                                    res = dl.ToString();

                                                    //
                                                    //if (id != 0)
                                                    //{
                                                    //    zb[id] = dtDL.Rows[i]["参数名"].ToString();
                                                    //    un[id] = dtDL.Rows[i]["单位"].ToString();
                                                    //    lay[id] = dtDL.Rows[i]["设计值"].ToString();

                                                    //    dv[id] += sh.ShowPoint(res, num) + ',';
                                                    //    dvExcel[id] += res + ',';
                                                    

                                                    if (ParaID != "")
                                                    {
                                                        if (htUn.ContainsKey(ParaID))
                                                        {
                                                            htUn.Remove(ParaID);
                                                            htUn.Add(ParaID, res);
                                                        }
                                                        else
                                                            htUn.Add(ParaID, res);
                                                    }
                                                }
                                            }

                                            #endregion

                                            #region SQL

                                            sql = "select * from T_sheet_ZsheetPara where 报表名称='" + repName + "'  and 班组=" + bzID + "  and 机组=" + unit + " and 参数类型='SQL' and 公式级别=" + gsjb;

                                            DataTable dtSQL = null;

                                            if (rlDBType == "SQL")
                                                dtSQL = DBsql.RunDataTable(sql, out errMsg);
                                            else
                                                dtSQL = DBdb2.RunDataTable(sql, out errMsg);

                                            if (dtSQL != null && dtSQL.Rows.Count > 0)
                                            {
                                                for (int i = 0; i < dtSQL.Rows.Count; i++)
                                                {
                                                    //小数点数
                                                    num = dtSQL.Rows[i]["小数点数"].ToString();
                                                    //参数顺序
                                                    id = int.Parse(dtSQL.Rows[i]["参数顺序"].ToString());
                                                    //参数ID
                                                    ParaID = dtSQL.Rows[i]["参数ID"].ToString();

                                                    sql = dtSQL.Rows[i]["SQL语句"].ToString();

                                                    if (sql.Contains("&BZ&"))
                                                    {
                                                        sql = sql.Replace("&BZ&", bzID);
                                                        sql = sql.Replace("&bt&", DateTime.Parse(bTime).ToString("yyyy-MM-dd 0:00:00"));
                                                        sql = sql.Replace("&et&", DateTime.Parse(eTime).ToString("yyyy-MM-dd H:mm:ss"));
                                                    }
                                                    else if (sql.Contains("&bt&") && sql.Contains("&et&"))
                                                    {
                                                        sql = sql.Replace("&bt&", bTime);
                                                        sql = sql.Replace("&et&", DateTime.Parse(eTime).ToString("yyyy-MM-dd H:mm:ss"));
                                                    }

                                                    if (rlDBType == "SQL")
                                                        obj = DBsql.RunSingle(sql, out errMsg);
                                                    else
                                                        obj = DBdb2.RunSingle(sql, out errMsg);

                                                    res = "";
                                                    if (obj != null && obj.ToString() != "")
                                                    {
                                                        if (obj.ToString() != "")
                                                            res = obj.ToString();
                                                        else
                                                            res = "0";
                                                    }
                                                    else
                                                    { res = "0"; }

                                                    if (ParaID != "")
                                                    {
                                                        if (htUn.ContainsKey(ParaID))
                                                        {
                                                            htUn.Remove(ParaID);
                                                            htUn.Add(ParaID, res);
                                                        }
                                                        else
                                                            htUn.Add(ParaID, res);
                                                    }

                                                }
                                            }
                                            #endregion

                                            #region 存储过程

                                            sql = "select * from T_sheet_ZsheetPara where 报表名称='" + repName + "' and 班组=" + bzID + "  and 机组=" + unit + " and 参数类型='存储过程' and 公式级别=" + gsjb;

                                            DataTable dtSP = null;

                                            if (rlDBType == "SQL")
                                                dtSP = DBsql.RunDataTable(sql, out errMsg);
                                            else
                                                dtSP = DBdb2.RunDataTable(sql, out errMsg);

                                            if (dtSP != null && dtSP.Rows.Count > 0)
                                            {
                                                for (int i = 0; i < dtSP.Rows.Count; i++)
                                                {
                                                    //小数点数
                                                    num = dtSP.Rows[i]["小数点数"].ToString();
                                                    //参数顺序
                                                    id = int.Parse(dtSP.Rows[i]["参数顺序"].ToString());
                                                    //参数ID
                                                    ParaID = dtSP.Rows[i]["参数ID"].ToString();

                                                    spName = dtSP.Rows[i]["SQL语句"].ToString();

                                                    string paras = dtSP.Rows[i]["公式参数"].ToString();

                                                    if (paras != "" && paras != null)
                                                        value = pm.RetMonSPPara(paras, htGY, htUn);


                                                    if (rlDBType == "SQL")
                                                        obj = DBsql.RunSingle_SP(spName, dtSP.Rows[i]["ID_KEY"].ToString(), bTime, eTime, bzID, paras, value, out errMsg);
                                                    else
                                                        obj = DBdb2.RunSingle_SP(spName, dtSP.Rows[i]["ID_KEY"].ToString(), bTime, eTime, bzID, paras, value, out errMsg);

                                                    if (obj != null && obj.ToString() != "")
                                                    {
                                                        if (obj.ToString() != "")
                                                            res = obj.ToString();
                                                        else
                                                            res = "0";
                                                    }
                                                    else
                                                    { res = "0"; }

                                                    if (ParaID != "")
                                                    {
                                                        if (htUn.ContainsKey(ParaID))
                                                        {
                                                            htUn.Remove(ParaID);
                                                            htUn.Add(ParaID, res);
                                                        }
                                                        else
                                                            htUn.Add(ParaID, res);
                                                    }
                                                }
                                            }
                                            #endregion

                                            #region 其它
                                            sql = "select * from T_sheet_ZsheetPara where 报表名称='" + repName + "' and 班组=" + bzID + " and 机组=" + unit + " and 参数类型='其它' and 公式级别=" + gsjb;

                                            DataTable dtQT = null;

                                            if (rlDBType == "SQL")
                                                dtQT = DBsql.RunDataTable(sql, out errMsg);
                                            else
                                                dtQT = DBdb2.RunDataTable(sql, out errMsg);

                                            if (dtQT.Rows.Count > 0 && dtQT != null)
                                            {
                                                for (int i = 0; i < dtQT.Rows.Count; i++)
                                                {
                                                    //小数点数
                                                    num = dtQT.Rows[i]["小数点数"].ToString();
                                                    //参数顺序
                                                    id = int.Parse(dtQT.Rows[i]["参数顺序"].ToString());
                                                    //参数ID
                                                    ParaID = dtQT.Rows[i]["参数ID"].ToString();

                                                    #region 购网电量
                                                    if (dtQT.Rows[i]["参数名"].ToString() == "购网电量")
                                                    {
                                                        //string re = um.gwdl(qsrq, jsrq, unit);

                                                        //if (dtQT.Rows[i]["显示"].ToString() == "1")
                                                        //{
                                                        //    id = int.Parse(dtQT.Rows[i]["参数顺序"].ToString());

                                                        //    dv[id] += sh.ShowPoint(re.ToString(), num) + ",";

                                                        //    dvExcel[id] += sh.ShowPoint(re.ToString(), "-1") + ",";
                                                        //}

                                                        //if (dtQT.Rows[i]["参数ID"].ToString() != "")
                                                        //{
                                                        //    id = int.Parse(dtQT.Rows[i]["参数key"].ToString());

                                                        //    du[id] += dtQT.Rows[i]["参数ID"].ToString() + "," + re + ";";
                                                        //}
                                                    }
                                                    #endregion

                                                    #region 入炉煤低位发热量
                                                    if (dtQT.Rows[i]["参数名"].ToString() == "入炉煤低位发热量")
                                                    {
                                                        //string rlm = um.rlmdwfrl("值报", DateTime.Parse(qsrq).ToString("yyyy-MM-dd 0:00:00"), jsrq, unit, dtLevBZ.Rows[k]["班组编号"].ToString());

                                                        //if (dtQT.Rows[i]["显示"].ToString() == "1")
                                                        //{
                                                        //    id = int.Parse(dtQT.Rows[i]["参数顺序"].ToString());

                                                        //    dv[id] += sh.ShowPoint(rlm, num) + ",";

                                                        //    dvExcel[id] += sh.ShowPoint(rlm, "-1") + ",";
                                                        //}

                                                        //if (dtQT.Rows[i]["参数ID"].ToString() != "")
                                                        //{
                                                        //    id = int.Parse(dtQT.Rows[i]["参数key"].ToString());

                                                        //    //du[id] += dtQT.Rows[i]["参数ID"].ToString() + "," + sh.ShowPoint(rlm, num) + ";";

                                                        //    du[id] += dtQT.Rows[i]["参数ID"].ToString() + "," + rlm + ";";
                                                        //}
                                                    }
                                                    #endregion
                                                }
                                            }
                                            #endregion

                                            #region 公式
                                            sql = "select * from T_sheet_ZsheetPara where 报表名称='" + repName + "'  and 班组=" + bzID + "  and 机组=" + unit + " and 参数类型='公式' and 公式级别=" + gsjb;

                                            DataTable dtMon = null;

                                            if (rlDBType == "SQL")
                                                dtMon = DBsql.RunDataTable(sql, out errMsg);
                                            else
                                                dtMon = DBdb2.RunDataTable(sql, out errMsg);

                                            if (dtMon != null && dtMon.Rows.Count > 0)
                                            {
                                                for (int i = 0; i < dtMon.Rows.Count; i++)
                                                {
                                                    //小数点数
                                                    num = dtMon.Rows[i]["小数点数"].ToString();
                                                    //参数顺序
                                                    id = int.Parse(dtMon.Rows[i]["参数顺序"].ToString());
                                                    //参数ID
                                                    ParaID = dtMon.Rows[i]["参数ID"].ToString();

                                                    string pMon = dtMon.Rows[i]["公式"].ToString();

                                                    string paras = dtMon.Rows[i]["公式参数"].ToString();

                                                    string month = pm.retMonByValPara(htGY, htUn, paras, pMon);

                                                    if (month != "")
                                                    {
                                                        res = "";
                                                        try
                                                        { res = StrHelper.Cale(month); }
                                                        catch
                                                        {
                                                            res = "0";
                                                            LogHelper.WriteLog(LogHelper.EnLogType.Run, DateTime.Now.ToString("yyyy-MM-dd H:mm:ss") + " 日值 公式 报程序异常: " + pMon + ":" + paras + ":" + month);
                                                        }

                                                        if (ParaID != "")
                                                        {
                                                            if (htUn.ContainsKey(ParaID))
                                                            {
                                                                htUn.Remove(ParaID);
                                                                htUn.Add(ParaID, res);
                                                            }
                                                            else
                                                                htUn.Add(ParaID, res);
                                                        }
                                                    }
                                                }
                                            }

                                            #endregion
                                        }
                                    }
                                }
                            }
                        }
                    }
                    LogHelper.WriteLog(LogHelper.EnLogType.Run, DateTime.Now.ToString("yyyy-MM-dd H:mm:ss") + "---" + repName + "----" + repType + "----机组轮转结束!");
                }
                #endregion

                #region 全厂数据读取
                unit = "0";

                //sql = "SELECT DISTINCT 班组 FROM T_sheet_ZsheetPara where 报表名称='" + repName + "' and 班组 !=0 and 机组=" + unit;
                //sql = "select * from 排班表 where 起始时间 between '" + bTime + "' and '" + eTime + "'";

                if (type == "zr")
                    sql = "select 班组编号 from 排班表 where 起始时间 between '" + bTime + "' and '" + eTime + "'";
                else
                    sql = "select 班组编号 from 班组表";

                if (rlDBType == "SQL")
                    dtBZ = DBsql.RunDataTable(sql, out errMsg);
                else if (rlDBType == "DB2")
                    dtBZ = DBdb2.RunDataTable(sql, out errMsg);

                if (dtBZ.Rows.Count > 0)
                {
                    LogHelper.WriteLog(LogHelper.EnLogType.Run, DateTime.Now.ToString("yyyy-MM-dd H:mm:ss") + "---" + repName + "----" + repType + "----全厂数据取值开始!");

                    for (int j = 0; j < dtBZ.Rows.Count; j++)
                    {
                        //string bz = dtBZ.Rows[j]["班组"].ToString();
                        string bz = dtBZ.Rows[j]["班组编号"].ToString();

                        BZ += dtBZ.Rows[j]["班组编号"].ToString() + ",";

                        sql = "select * from 排班表 where 起始时间 between '" + bTime + "' and '" + eTime + "' and 班组编号='" + bz + "'";

                        if (rlDBType == "SQL")
                            dtISPB = DBsql.RunDataTable(sql, out errMsg);
                        else if (rlDBType == "DB2")
                            dtISPB = DBdb2.RunDataTable(sql, out errMsg);

                        if (dtISPB != null && dtISPB.Rows.Count > 0)
                            flag = true;
                        else
                            flag = false;

                        if (flag == false)
                        {
                            #region  非当班班组值获取
                            sql = "select * from T_sheet_ZsheetPara where 报表名称='" + repName + "' and 班组=" + bz + " and 机组=" + unit;

                            DataTable dtNotPB = null;

                            if (rlDBType == "SQL")
                                dtNotPB = DBsql.RunDataTable(sql, out errMsg);
                            else
                                dtNotPB = DBdb2.RunDataTable(sql, out errMsg);

                            if (dtNotPB != null && dtNotPB.Rows.Count > 0)
                            {
                                for (int i = 0; i < dtNotPB.Rows.Count; i++)
                                {
                                    //小数点数
                                    num = dtNotPB.Rows[i]["小数点数"].ToString();
                                    //参数顺序
                                    id = int.Parse(dtNotPB.Rows[i]["参数顺序"].ToString());
                                    //参数ID
                                    ParaID = dtNotPB.Rows[i]["参数ID"].ToString();

                                    if (id != 0)
                                    {
                                        zb[id] = dtNotPB.Rows[i]["参数名"].ToString();
                                        un[id] = dtNotPB.Rows[i]["单位"].ToString();
                                        lay[id] = dtNotPB.Rows[i]["设计值"].ToString();

                                        dv[id] += "0,";
                                        dvExcel[id] += "0,";
                                    }

                                    if (ParaID != "")
                                    {
                                        if (htUn.ContainsKey(ParaID))
                                        {
                                            htUn.Remove(ParaID);
                                            htUn.Add(ParaID, "0");
                                        }
                                        else
                                            htUn.Add(ParaID, "0");
                                    }
                                }
                            }
                            #endregion
                        }
                        else
                        {
                            sql = "SELECT DISTINCT 公式级别 FROM T_sheet_ZsheetPara where 报表名称='" + repName + "' and 班组=" + bz + " and 机组 =" + unit + " and 公式级别!=0";

                            if (rlDBType == "SQL")
                                dtLel = DBsql.RunDataTable(sql, out errMsg);
                            else if (rlDBType == "DB2")
                                dtLel = DBdb2.RunDataTable(sql, out errMsg);

                            if (dtLel.Rows.Count > 0)
                            {
                                for (int k = 0; k < dtLel.Rows.Count; k++)
                                {
                                    //公式级别
                                    gsjb = dtLel.Rows[k]["公式级别"].ToString();

                                    #region 平均
                                    sql = "select * from T_sheet_ZsheetPara where 报表名称='" + repName + "' and 班组=" + bz + " and 机组=" + unit + " and 参数类型='平均' and 公式级别=" + gsjb;

                                    DataTable dtAvg = null;

                                    if (rlDBType == "SQL")
                                        dtAvg = DBsql.RunDataTable(sql, out errMsg);
                                    else
                                        dtAvg = DBdb2.RunDataTable(sql, out errMsg);

                                    if (dtAvg != null && dtAvg.Rows.Count > 0)
                                    {
                                        for (int i = 0; i < dtAvg.Rows.Count; i++)
                                        {
                                            //小数点数
                                            num = dtAvg.Rows[i]["小数点数"].ToString();
                                            //参数顺序
                                            id = int.Parse(dtAvg.Rows[i]["参数顺序"].ToString());
                                            //参数ID
                                            ParaID = dtAvg.Rows[i]["参数ID"].ToString();

                                            if (dtAvg.Rows[i]["统计ID"].ToString() != "")
                                                sql = "select 统计值 from " + bName + " where 时间='" + bTime + "' and 机组=" + unit + " and 班组=" + bz + " and 统计ID ='" + dtAvg.Rows[i]["统计ID"].ToString() + "'";
                                            else
                                                LogHelper.WriteLog(LogHelper.EnLogType.Run, DateTime.Now.ToString("yyyy-MM-dd H:mm:ss") + " 日值 平均 报程序异常: 班组编号 || 统计ID 为空" + sql);

                                            if (rlDBType == "SQL")
                                                objVal = DBsql.RunSingle(sql, out errMsg);
                                            else
                                                objVal = DBdb2.RunSingle(sql, out errMsg);

                                            res = "";
                                            if (objVal != null && objVal != "")
                                            {
                                                if (objVal.ToString() != "")
                                                    res = objVal.ToString();
                                                else
                                                    res = "0";
                                            }
                                            else
                                            { res = "0"; }

                                            if (id != 0)
                                            {
                                                zb[id] = dtAvg.Rows[i]["参数名"].ToString();
                                                un[id] = dtAvg.Rows[i]["单位"].ToString();
                                                lay[id] = dtAvg.Rows[i]["设计值"].ToString();

                                                dv[id] += sh.ShowPoint(res, num) + ',';
                                                dvExcel[id] += res + ',';
                                            }

                                            if (ParaID != "")
                                            {
                                                if (htUn.ContainsKey(ParaID))
                                                {
                                                    htUn.Remove(ParaID);
                                                    htUn.Add(ParaID, res);
                                                }
                                                else
                                                    htUn.Add(ParaID, res);
                                            }
                                        }
                                    }
                                    #endregion

                                    #region 累计
                                    sql = "select * from T_sheet_ZsheetPara where 报表名称='" + repName + "' and 班组=" + bz + " and 机组=" + unit + " and 参数类型='累计' and 公式级别=" + gsjb;

                                    DataTable dtDiff = null;

                                    if (rlDBType == "SQL")
                                        dtDiff = DBsql.RunDataTable(sql, out errMsg);
                                    else
                                        dtDiff = DBdb2.RunDataTable(sql, out errMsg);

                                    if (dtDiff != null && dtDiff.Rows.Count > 0)
                                    {
                                        for (int i = 0; i < dtDiff.Rows.Count; i++)
                                        {
                                            //小数点数
                                            num = dtDiff.Rows[i]["小数点数"].ToString();
                                            //参数顺序
                                            id = int.Parse(dtDiff.Rows[i]["参数顺序"].ToString());
                                            //参数ID
                                            ParaID = dtDiff.Rows[i]["参数ID"].ToString();

                                            if (dtDiff.Rows[i]["统计ID"].ToString() != "")
                                                sql = "select 统计值 from " + bName + " where 时间='" + bTime + "' and 机组=" + unit + " and 班组=" + bz + " and 统计ID ='" + dtDiff.Rows[i]["统计ID"].ToString() + "'";
                                            else
                                                LogHelper.WriteLog(LogHelper.EnLogType.Run, DateTime.Now.ToString("yyyy-MM-dd H:mm:ss") + " 日值 平均 报程序异常: 班组编号 || 统计ID 为空" + sql);

                                            if (rlDBType == "SQL")
                                                objVal = DBsql.RunSingle(sql, out errMsg);
                                            else
                                                objVal = DBdb2.RunSingle(sql, out errMsg);

                                            res = "";
                                            if (objVal != null && objVal != "")
                                            {
                                                if (objVal.ToString() != "")
                                                    res = objVal.ToString();
                                                else
                                                    res = "0";
                                            }
                                            else
                                            { res = "0"; }

                                            if (id != 0)
                                            {
                                                zb[id] = dtDiff.Rows[i]["参数名"].ToString();
                                                un[id] = dtDiff.Rows[i]["单位"].ToString();
                                                lay[id] = dtDiff.Rows[i]["设计值"].ToString();

                                                dv[id] += sh.ShowPoint(res, num) + ',';
                                                dvExcel[id] += res + ',';
                                            }

                                            if (ParaID != "")
                                            {
                                                if (htUn.ContainsKey(ParaID))
                                                {
                                                    htUn.Remove(ParaID);
                                                    htUn.Add(ParaID, res);
                                                }
                                                else
                                                    htUn.Add(ParaID, res);
                                            }
                                        }
                                    }
                                    #endregion

                                    #region 电量
                                    sql = "select * from T_sheet_ZsheetPara where 报表名称='" + repName + "' and 班组=" + bz + "  and 机组=" + unit + " and 参数类型='电量' and 公式级别=" + gsjb;

                                    DataTable dtDL = null;

                                    if (rlDBType == "SQL")
                                        dtDL = DBsql.RunDataTable(sql, out errMsg);
                                    else
                                        dtDL = DBdb2.RunDataTable(sql, out errMsg);

                                    if (dtDL.Rows.Count > 0 && dtDL != null)
                                    {
                                        for (int i = 0; i < dtDL.Rows.Count; i++)
                                        {
                                            dlID = dtDL.Rows[i]["电量点"].ToString();
                                            //小数点数
                                            num = dtDL.Rows[i]["小数点数"].ToString();
                                            //参数顺序
                                            id = int.Parse(dtDL.Rows[i]["参数顺序"].ToString());
                                            //参数ID
                                            ParaID = dtDL.Rows[i]["参数ID"].ToString();

                                            //sql = "select * from 排班表 where 起始时间 between '" + bTime + "' and '" + eTime + "' and 班组编号='" + bz + "' union select * from 排班表 where 结束时间 between '" + bTime + "' and '" + eTime + "' and 班组编号='" + bz + "'";

                                            //DataTable dtPB = null;

                                            //if (rlDBType == "SQL")
                                            //    dtPB = DBsql.RunDataTable(sql, out errMsg);
                                            //else
                                            //    dtPB = DBdb2.RunDataTable(sql, out errMsg);

                                            //mon = "";

                                            //if (dtPB != null && dtPB.Rows.Count > 0)
                                            //{
                                            //    string monDL = "0+";

                                            //    for (int q = 0; q < dtPB.Rows.Count; q++)
                                            //    {
                                            //        string qt = dtPB.Rows[q]["起始时间"].ToString();
                                            //        string jt = dtPB.Rows[q]["结束时间"].ToString();

                                            //        drvA = double.Parse(pc.GetPower(drvA, dlID, DateTime.Parse(qt).ToString("yyyy-MM-dd H:00:00"), DateTime.Parse(jt).AddSeconds(+1).ToString("yyyy-MM-dd H:00:00"), bm).ToString());

                                            //        monDL += drvA.ToString() + "+";
                                            //    }
                                            //    mon = monDL.TrimEnd('+');

                                            //    if (dtDL.Rows[i]["公式"].ToString() != "")
                                            //        mon = "(" + mon + ")" + dtDL.Rows[i]["公式"].ToString();
                                            //}

                                            //res = "";
                                            //try
                                            //{ res = StrHelper.Cale(mon); }
                                            //catch
                                            //{ res = "0"; }


                                            //

                                            //电量
                                            double dl = 0;
                                            double sdl = 0;
                                            double edl = 0;

                                            if (dlID != "")
                                            {
                                                sql = " select * from 排班表 where 起始时间 between '" + bTime + "' and '" + eTime + "' and 班组编号='" + bz + "' union select * from 排班表 where 结束时间 between '" + bTime + "' and '" + eTime + "' and 班组编号='" + bz + "'";

                                                DataTable dtPB = null;

                                                if (rlDBType == "SQL")
                                                    dtPB = DBsql.RunDataTable(sql, out errMsg);
                                                else
                                                    dtPB = DBdb2.RunDataTable(sql, out errMsg);

                                                mon = "";

                                                string startTime = "";
                                                string endTime = "";
                                                if (dtPB != null && dtPB.Rows.Count > 0)
                                                {
                                                    string monDL = "0+";

                                                    for (int q = 0; q < dtPB.Rows.Count; q++)
                                                    {
                                                        startTime += "'" + dtPB.Rows[q]["起始时间"].ToString().Trim() + "',";
                                                        endTime += "'" + DateTime.Parse(dtPB.Rows[q]["结束时间"].ToString().Trim()).AddSeconds(+1).ToString() + "',";
                                                    }
                                                }

                                                startTime = startTime.Substring(0, startTime.Length - 1);
                                                endTime = endTime.Substring(0, endTime.Length - 1);


                                                //表码值
                                                object sbm = null;
                                                object ebm = null;
                                                string sqlsbm = "SELECT sum(表码值) as 表码 FROM ADMINISTRATOR.设备表码数据表 where  设备ID='" + dlID + "'  and 时间 in(" + startTime + ")";
                                                string sqlebm = "SELECT sum(表码值) as 表码 FROM ADMINISTRATOR.设备表码数据表 where  设备ID='" + dlID + "'  and 时间 in(" + endTime + ")";
                                                //换表表码
                                                object hbsbm = null;
                                                object hbebm = null;
                                                string sqlhbsbm = "SELECT sum(表码值) as 表码 FROM ADMINISTRATOR.设备换表起码数据表 where  设备ID='" + dlID + "'  and 时间 in(" + startTime + ")";
                                                string sqlhbebm = "SELECT sum(表码值) as 表码 FROM ADMINISTRATOR.设备换表起码数据表 where  设备ID='" + dlID + "'  and 时间 in(" + endTime + ")";

                                                //倍率
                                                string sqlbl = "SELECT 倍率 FROM ADMINISTRATOR.设备倍率表 where 设备ID='" + dlID + "'";
                                                double bl = 1;
                                                //表码上限
                                                string sqlbmsx = "SELECT 表码上限 FROM ADMINISTRATOR.设备表码上限表 where 设备ID='" + dlID + "'";
                                                double sx = 0;

                                                if (rlDBType == "SQL")
                                                {
                                                    sbm = DBsql.RunSingle(sqlsbm, out errMsg);
                                                    ebm = DBsql.RunSingle(sqlebm, out errMsg);
                                                    hbsbm = DBsql.RunSingle(sqlhbsbm, out errMsg);
                                                    hbebm = DBsql.RunSingle(sqlhbebm, out errMsg);
                                                    bl = Convert.ToDouble(DBsql.RunSingle(sqlbl, out errMsg).ToString());
                                                    sx = Convert.ToDouble(DBsql.RunSingle(sqlbmsx, out errMsg).ToString());
                                                }
                                                else
                                                {
                                                    sbm = DBdb2.RunSingle(sqlsbm, out errMsg);
                                                    ebm = DBdb2.RunSingle(sqlebm, out errMsg);
                                                    hbsbm = DBdb2.RunSingle(sqlhbsbm, out errMsg);
                                                    hbebm = DBdb2.RunSingle(sqlhbebm, out errMsg);
                                                    bl = Convert.ToDouble(DBdb2.RunSingle(sqlbl, out errMsg).ToString());
                                                    sx = Convert.ToDouble(DBdb2.RunSingle(sqlbmsx, out errMsg).ToString());
                                                }

                                                if (sbm != null && sbm.ToString() != "")
                                                    if (hbsbm != null && hbsbm.ToString()!="")
                                                        sdl = Convert.ToDouble(sbm.ToString()) + Convert.ToDouble(hbsbm.ToString());
                                                    else
                                                        sdl = Convert.ToDouble(sbm.ToString());
                                                else
                                                { sdl = 0; }

                                                if (ebm != null && ebm.ToString() != "")
                                                    if (hbebm != null && hbebm.ToString() != "")
                                                        edl = Convert.ToDouble(ebm.ToString()) + Convert.ToDouble(hbebm.ToString());
                                                    else
                                                        edl = Convert.ToDouble(ebm.ToString());
                                                else
                                                { edl = 0; }
                                                if (edl - sdl >= 0)
                                                {
                                                    dl = (edl - sdl) * bl;
                                                }
                                                else
                                                {
                                                    dl = (edl - sdl + sx) * bl;
                                                }
                                            }

                                            res = dl.ToString();

                                            //
                                            if (id != 0)
                                            {
                                                zb[id] = dtDL.Rows[i]["参数名"].ToString();
                                                un[id] = dtDL.Rows[i]["单位"].ToString();
                                                lay[id] = dtDL.Rows[i]["设计值"].ToString();

                                                dv[id] += sh.ShowPoint(res, num) + ',';
                                                dvExcel[id] += res + ',';
                                            }

                                            if (ParaID != "")
                                            {
                                                if (htUn.ContainsKey(ParaID))
                                                {
                                                    htUn.Remove(ParaID);
                                                    htUn.Add(ParaID, res);
                                                }
                                                else
                                                    htUn.Add(ParaID, res);
                                            }
                                        }
                                    }

                                    #endregion

                                    #region SQL

                                    sql = "select * from T_sheet_ZsheetPara where 报表名称='" + repName + "'  and 班组=" + bz + "  and 机组=" + unit + " and 参数类型='SQL' and 公式级别=" + gsjb;

                                    DataTable dtSQL = null;

                                    if (rlDBType == "SQL")
                                        dtSQL = DBsql.RunDataTable(sql, out errMsg);
                                    else
                                        dtSQL = DBdb2.RunDataTable(sql, out errMsg);

                                    if (dtSQL != null && dtSQL.Rows.Count > 0)
                                    {
                                        for (int i = 0; i < dtSQL.Rows.Count; i++)
                                        {
                                            //小数点数
                                            num = dtSQL.Rows[i]["小数点数"].ToString();
                                            //参数顺序
                                            id = int.Parse(dtSQL.Rows[i]["参数顺序"].ToString());
                                            //参数ID
                                            ParaID = dtSQL.Rows[i]["参数ID"].ToString();

                                            sql = dtSQL.Rows[i]["SQL语句"].ToString();

                                            if (sql.Contains("&BZ&"))
                                            {
                                                sql = sql.Replace("&BZ&", bz);
                                                sql = sql.Replace("&bt&", DateTime.Parse(bTime).ToString("yyyy-MM-dd 0:00:00"));
                                                sql = sql.Replace("&et&", DateTime.Parse(eTime).ToString("yyyy-MM-dd H:mm:ss"));
                                            }
                                            else if (sql.Contains("&bt&") && sql.Contains("&et&"))
                                            {
                                                sql = sql.Replace("&bt&", bTime);
                                                sql = sql.Replace("&et&", DateTime.Parse(eTime).ToString("yyyy-MM-dd H:mm:ss"));
                                            }

                                            if (rlDBType == "SQL")
                                                obj = DBsql.RunSingle(sql, out errMsg);
                                            else
                                                obj = DBdb2.RunSingle(sql, out errMsg);

                                            res = "";
                                            if (obj != null && obj.ToString() != "")
                                            {
                                                if (obj.ToString() != "")
                                                    res = obj.ToString();
                                                else
                                                    res = "0";
                                            }
                                            else
                                            { res = "0"; }

                                            if (id != 0)
                                            {
                                                zb[id] = dtSQL.Rows[i]["参数名"].ToString();
                                                un[id] = dtSQL.Rows[i]["单位"].ToString();
                                                lay[id] = dtSQL.Rows[i]["设计值"].ToString();

                                                dv[id] += sh.ShowPoint(res, num) + ',';
                                                dvExcel[id] += res + ',';
                                            }

                                            if (ParaID != "")
                                            {
                                                if (htUn.ContainsKey(ParaID))
                                                {
                                                    htUn.Remove(ParaID);
                                                    htUn.Add(ParaID, res);
                                                }
                                                else
                                                    htUn.Add(ParaID, res);
                                            }

                                        }
                                    }
                                    #endregion

                                    #region 存储过程

                                    sql = "select * from T_sheet_ZsheetPara where 报表名称='" + repName + "' and 班组=" + bz + "  and 机组=" + unit + " and 参数类型='存储过程' and 公式级别=" + gsjb;

                                    DataTable dtSP = null;

                                    if (rlDBType == "SQL")
                                        dtSP = DBsql.RunDataTable(sql, out errMsg);
                                    else
                                        dtSP = DBdb2.RunDataTable(sql, out errMsg);

                                    if (dtSP != null && dtSP.Rows.Count > 0)
                                    {
                                        for (int i = 0; i < dtSP.Rows.Count; i++)
                                        {
                                            //小数点数
                                            num = dtSP.Rows[i]["小数点数"].ToString();
                                            //参数顺序
                                            id = int.Parse(dtSP.Rows[i]["参数顺序"].ToString());
                                            //参数ID
                                            ParaID = dtSP.Rows[i]["参数ID"].ToString();

                                            spName = dtSP.Rows[i]["SQL语句"].ToString();

                                            string paras = dtSP.Rows[i]["公式参数"].ToString();

                                            if (paras != "" && paras != null)
                                                value = pm.RetMonSPPara(paras, htGY, htUn);


                                            if (rlDBType == "SQL")
                                                obj = DBsql.RunSingle_SP(spName, dtSP.Rows[i]["ID_KEY"].ToString(), bTime, eTime, bz, paras, value, out errMsg);
                                            else
                                                obj = DBdb2.RunSingle_SP(spName, dtSP.Rows[i]["ID_KEY"].ToString(), bTime, eTime, bz, paras, value, out errMsg);

                                            if (obj != null && obj.ToString() != "")
                                            {
                                                if (obj.ToString() != "")
                                                    res = obj.ToString();
                                                else
                                                    res = "0";
                                            }
                                            else
                                            { res = "0"; }

                                            if (id != 0)
                                            {
                                                zb[id] = dtSP.Rows[i]["参数名"].ToString();
                                                un[id] = dtSP.Rows[i]["单位"].ToString();
                                                lay[id] = dtSP.Rows[i]["设计值"].ToString();

                                                dv[id] += sh.ShowPoint(res, num) + ',';
                                                dvExcel[id] += res + ',';
                                            }

                                            if (ParaID != "")
                                            {
                                                if (htUn.ContainsKey(ParaID))
                                                {
                                                    htUn.Remove(ParaID);
                                                    htUn.Add(ParaID, res);
                                                }
                                                else
                                                    htUn.Add(ParaID, res);
                                            }
                                        }
                                    }
                                    #endregion

                                    #region 其它
                                    sql = "select * from T_sheet_ZsheetPara where 报表名称='" + repName + "' and 班组=" + bz + " and 机组=" + unit + " and 参数类型='其它' and 公式级别=" + gsjb;

                                    DataTable dtQT = null;

                                    if (rlDBType == "SQL")
                                        dtQT = DBsql.RunDataTable(sql, out errMsg);
                                    else
                                        dtQT = DBdb2.RunDataTable(sql, out errMsg);

                                    if (dtQT.Rows.Count > 0 && dtQT != null)
                                    {
                                        for (int i = 0; i < dtQT.Rows.Count; i++)
                                        {
                                            //小数点数
                                            num = dtQT.Rows[i]["小数点数"].ToString();
                                            //参数顺序
                                            id = int.Parse(dtQT.Rows[i]["参数顺序"].ToString());
                                            //参数ID
                                            ParaID = dtQT.Rows[i]["参数ID"].ToString();

                                            #region 购网电量
                                            if (dtQT.Rows[i]["参数名"].ToString() == "购网电量")
                                            {
                                                //string re = um.gwdl(qsrq, jsrq, unit);

                                                //if (dtQT.Rows[i]["显示"].ToString() == "1")
                                                //{
                                                //    id = int.Parse(dtQT.Rows[i]["参数顺序"].ToString());

                                                //    dv[id] += sh.ShowPoint(re.ToString(), num) + ",";

                                                //    dvExcel[id] += sh.ShowPoint(re.ToString(), "-1") + ",";
                                                //}

                                                //if (dtQT.Rows[i]["参数ID"].ToString() != "")
                                                //{
                                                //    id = int.Parse(dtQT.Rows[i]["参数key"].ToString());

                                                //    du[id] += dtQT.Rows[i]["参数ID"].ToString() + "," + re + ";";
                                                //}
                                            }
                                            #endregion

                                            #region 入炉煤低位发热量
                                            if (dtQT.Rows[i]["参数名"].ToString() == "入炉煤低位发热量")
                                            {
                                                //string rlm = um.rlmdwfrl("值报", DateTime.Parse(qsrq).ToString("yyyy-MM-dd 0:00:00"), jsrq, unit, dtLevBZ.Rows[k]["班组编号"].ToString());

                                                //if (dtQT.Rows[i]["显示"].ToString() == "1")
                                                //{
                                                //    id = int.Parse(dtQT.Rows[i]["参数顺序"].ToString());

                                                //    dv[id] += sh.ShowPoint(rlm, num) + ",";

                                                //    dvExcel[id] += sh.ShowPoint(rlm, "-1") + ",";
                                                //}

                                                //if (dtQT.Rows[i]["参数ID"].ToString() != "")
                                                //{
                                                //    id = int.Parse(dtQT.Rows[i]["参数key"].ToString());

                                                //    //du[id] += dtQT.Rows[i]["参数ID"].ToString() + "," + sh.ShowPoint(rlm, num) + ";";

                                                //    du[id] += dtQT.Rows[i]["参数ID"].ToString() + "," + rlm + ";";
                                                //}
                                            }
                                            #endregion
                                        }
                                    }
                                    #endregion

                                    #region 公式
                                    sql = "select * from T_sheet_ZsheetPara where 报表名称='" + repName + "'  and 班组=" + bz + "  and 机组=" + unit + " and 参数类型='公式' and 公式级别=" + gsjb;

                                    DataTable dtMon = null;

                                    if (rlDBType == "SQL")
                                        dtMon = DBsql.RunDataTable(sql, out errMsg);
                                    else
                                        dtMon = DBdb2.RunDataTable(sql, out errMsg);

                                    if (dtMon != null && dtMon.Rows.Count > 0)
                                    {
                                        for (int i = 0; i < dtMon.Rows.Count; i++)
                                        {
                                            //小数点数
                                            num = dtMon.Rows[i]["小数点数"].ToString();
                                            //参数顺序
                                            id = int.Parse(dtMon.Rows[i]["参数顺序"].ToString());
                                            //参数ID
                                            ParaID = dtMon.Rows[i]["参数ID"].ToString();

                                            string pMon = dtMon.Rows[i]["公式"].ToString();

                                            string paras = dtMon.Rows[i]["公式参数"].ToString();

                                            string month = pm.retMonByValPara(htGY, htUn, paras, pMon);

                                            if (month != "")
                                            {
                                                res = "";
                                                try
                                                { res = StrHelper.Cale(month); }
                                                catch
                                                {
                                                    res = "0";
                                                    LogHelper.WriteLog(LogHelper.EnLogType.Run, DateTime.Now.ToString("yyyy-MM-dd H:mm:ss") + " 日值 公式 报程序异常: " + pMon + ":" + paras + ":" + month);
                                                }

                                                if (id != 0)
                                                {
                                                    zb[id] = dtMon.Rows[i]["参数名"].ToString();
                                                    un[id] = dtMon.Rows[i]["单位"].ToString();
                                                    lay[id] = dtMon.Rows[i]["设计值"].ToString();

                                                    dv[id] += sh.ShowPoint(res, num) + ',';
                                                    dvExcel[id] += res + ',';
                                                }

                                                if (ParaID != "")
                                                {
                                                    if (htUn.ContainsKey(ParaID))
                                                    {
                                                        htUn.Remove(ParaID);
                                                        htUn.Add(ParaID, res);
                                                    }
                                                    else
                                                        htUn.Add(ParaID, res);
                                                }
                                            }
                                        }
                                    }

                                    #endregion
                                }
                            }
                        }
                    }
                    LogHelper.WriteLog(LogHelper.EnLogType.Run, DateTime.Now.ToString("yyyy-MM-dd H:mm:ss") + "---" + repName + "----" + repType + "----全厂数据取值结束!");
                }

                #endregion

                #region 横向计算

                sql = "SELECT DISTINCT 公式级别 FROM T_sheet_ZsheetPara where 报表名称='" + repName + "' and 班组=0 and  机组 =0 and 公式级别!=0";

                if (rlDBType == "SQL")
                    dtLel = DBsql.RunDataTable(sql, out errMsg);
                else if (rlDBType == "DB2")
                    dtLel = DBdb2.RunDataTable(sql, out errMsg);

                if (dtLel.Rows.Count > 0)
                {
                    LogHelper.WriteLog(LogHelper.EnLogType.Run, DateTime.Now.ToString("yyyy-MM-dd H:mm:ss") + "---" + repName + "----" + repType + "----全厂数据横向计算取值开始!");

                    for (int k = 0; k < dtLel.Rows.Count; k++)
                    {
                        //公式级别
                        gsjb = dtLel.Rows[k]["公式级别"].ToString();

                        #region 平均
                        sql = "select * from T_sheet_ZsheetPara where 报表名称='" + repName + "' and 班组=0 and 机组=0 and 参数类型='平均' and 公式级别=" + gsjb;

                        DataTable dtAvg = null;

                        if (rlDBType == "SQL")
                            dtAvg = DBsql.RunDataTable(sql, out errMsg);
                        else
                            dtAvg = DBdb2.RunDataTable(sql, out errMsg);

                        if (dtAvg != null && dtAvg.Rows.Count > 0)
                        {
                            for (int i = 0; i < dtAvg.Rows.Count; i++)
                            {
                                //小数点数
                                num = dtAvg.Rows[i]["小数点数"].ToString();
                                //参数顺序
                                id = int.Parse(dtAvg.Rows[i]["参数顺序"].ToString());
                                //参数ID
                                ParaID = dtAvg.Rows[i]["参数ID"].ToString();

                                if (dtAvg.Rows[i]["统计ID"].ToString() != "")
                                    sql = "select 统计值 from " + bName + " where 时间='" + bTime + "' and 机组=0 and 班组=0 and 统计ID ='" + dtAvg.Rows[i]["统计ID"].ToString() + "'";
                                else
                                    LogHelper.WriteLog(LogHelper.EnLogType.Run, DateTime.Now.ToString("yyyy-MM-dd H:mm:ss") + " 日值 平均 报程序异常: 班组编号 || 统计ID 为空" + sql);

                                if (rlDBType == "SQL")
                                    objVal = DBsql.RunSingle(sql, out errMsg);
                                else
                                    objVal = DBdb2.RunSingle(sql, out errMsg);

                                res = "";
                                if (objVal != null && objVal != "")
                                {
                                    if (objVal.ToString() != "")
                                        res = objVal.ToString();
                                    else
                                        res = "0";
                                }
                                else
                                { res = "0"; }

                                if (id != 0)
                                {
                                    zb[id] = dtAvg.Rows[i]["参数名"].ToString();
                                    un[id] = dtAvg.Rows[i]["单位"].ToString();
                                    lay[id] = dtAvg.Rows[i]["设计值"].ToString();

                                    dv[id] += sh.ShowPoint(res, num) + ',';
                                    dvExcel[id] += res + ',';
                                }

                                if (ParaID != "")
                                {
                                    if (htUn.ContainsKey(ParaID))
                                    {
                                        htUn.Remove(ParaID);
                                        htUn.Add(ParaID, res);
                                    }
                                    else
                                        htUn.Add(ParaID, res);
                                }
                            }
                        }
                        #endregion

                        #region 累计
                        sql = "select * from T_sheet_ZsheetPara where 报表名称='" + repName + "' and 班组=0 and 机组=0 and 参数类型='累计' and 公式级别=" + gsjb;

                        DataTable dtDiff = null;

                        if (rlDBType == "SQL")
                            dtDiff = DBsql.RunDataTable(sql, out errMsg);
                        else
                            dtDiff = DBdb2.RunDataTable(sql, out errMsg);

                        if (dtDiff != null && dtDiff.Rows.Count > 0)
                        {
                            for (int i = 0; i < dtDiff.Rows.Count; i++)
                            {
                                //小数点数
                                num = dtDiff.Rows[i]["小数点数"].ToString();
                                //参数顺序
                                id = int.Parse(dtDiff.Rows[i]["参数顺序"].ToString());
                                //参数ID
                                ParaID = dtDiff.Rows[i]["参数ID"].ToString();

                                if (dtDiff.Rows[i]["统计ID"].ToString() != "")
                                    sql = "select 统计值 from " + bName + " where 时间='" + bTime + "' and 机组=0 and 班组=0 and 统计ID ='" + dtDiff.Rows[i]["统计ID"].ToString() + "'";
                                else
                                    LogHelper.WriteLog(LogHelper.EnLogType.Run, DateTime.Now.ToString("yyyy-MM-dd H:mm:ss") + " 日值 平均 报程序异常: 班组编号 || 统计ID 为空" + sql);

                                if (rlDBType == "SQL")
                                    objVal = DBsql.RunSingle(sql, out errMsg);
                                else
                                    objVal = DBdb2.RunSingle(sql, out errMsg);

                                res = "";
                                if (objVal != null && objVal != "")
                                {
                                    if (objVal.ToString() != "")
                                        res = objVal.ToString();
                                    else
                                        res = "0";
                                }
                                else
                                { res = "0"; }

                                if (id != 0)
                                {
                                    zb[id] = dtDiff.Rows[i]["参数名"].ToString();
                                    un[id] = dtDiff.Rows[i]["单位"].ToString();
                                    lay[id] = dtDiff.Rows[i]["设计值"].ToString();

                                    dv[id] += sh.ShowPoint(res, num) + ',';
                                    dvExcel[id] += res + ',';
                                }

                                if (ParaID != "")
                                {
                                    if (htUn.ContainsKey(ParaID))
                                    {
                                        htUn.Remove(ParaID);
                                        htUn.Add(ParaID, res);
                                    }
                                    else
                                        htUn.Add(ParaID, res);
                                }
                            }
                        }
                        #endregion

                        #region 电量
                        sql = "select * from T_sheet_ZsheetPara where 报表名称='" + repName + "' and 班组=0  and 机组=0 and 参数类型='电量' and 公式级别=" + gsjb;

                        DataTable dtDL = null;

                        if (rlDBType == "SQL")
                            dtDL = DBsql.RunDataTable(sql, out errMsg);
                        else
                            dtDL = DBdb2.RunDataTable(sql, out errMsg);

                        if (dtDL.Rows.Count > 0 && dtDL != null)
                        {
                            for (int i = 0; i < dtDL.Rows.Count; i++)
                            {
                                dlID = dtDL.Rows[i]["电量点"].ToString();
                                //小数点数
                                num = dtDL.Rows[i]["小数点数"].ToString();
                                //参数顺序
                                id = int.Parse(dtDL.Rows[i]["参数顺序"].ToString());
                                //参数ID
                                ParaID = dtDL.Rows[i]["参数ID"].ToString();

                                sql = " select * from 排班表 where 起始时间 between '" + bTime + "' and '" + eTime + "' and 班组编号='0' union select * from 排班表 where 结束时间 between '" + bTime + "' and '" + eTime + "' and 班组编号='0'";

                                DataTable dtPB = null;

                                if (rlDBType == "SQL")
                                    dtPB = DBsql.RunDataTable(sql, out errMsg);
                                else
                                    dtPB = DBdb2.RunDataTable(sql, out errMsg);

                                mon = "";

                                if (dtPB != null && dtPB.Rows.Count > 0)
                                {
                                    string monDL = "0+";

                                    for (int q = 0; q < dtPB.Rows.Count; q++)
                                    {
                                        string qt = dtPB.Rows[q]["起始时间"].ToString();
                                        string jt = dtPB.Rows[q]["结束时间"].ToString();

                                        drvA = double.Parse(pc.GetPower(drvA, dlID, DateTime.Parse(qt).ToString("yyyy-MM-dd H:00:00"), DateTime.Parse(jt).AddSeconds(+1).ToString("yyyy-MM-dd H:00:00"), bm).ToString());

                                        monDL += drvA.ToString() + "+";
                                    }
                                    mon = monDL.TrimEnd('+');

                                    if (dtDL.Rows[i]["公式"].ToString() != "")
                                        mon = "(" + mon + ")" + dtDL.Rows[i]["公式"].ToString();
                                }

                                res = "";
                                try
                                { res = StrHelper.Cale(mon); }
                                catch
                                { res = "0"; }

                                if (id != 0)
                                {
                                    zb[id] = dtDL.Rows[i]["参数名"].ToString();
                                    un[id] = dtDL.Rows[i]["单位"].ToString();
                                    lay[id] = dtDL.Rows[i]["设计值"].ToString();

                                    dv[id] += sh.ShowPoint(res, num) + ',';
                                    dvExcel[id] += res + ',';
                                }

                                if (ParaID != "")
                                {
                                    if (htUn.ContainsKey(ParaID))
                                    {
                                        htUn.Remove(ParaID);
                                        htUn.Add(ParaID, res);
                                    }
                                    else
                                        htUn.Add(ParaID, res);
                                }
                            }
                        }

                        #endregion

                        #region SQL

                        sql = "select * from T_sheet_ZsheetPara where 报表名称='" + repName + "'  and 班组=0  and 机组=0 and 参数类型='SQL' and 公式级别=" + gsjb;

                        DataTable dtSQL = null;

                        if (rlDBType == "SQL")
                            dtSQL = DBsql.RunDataTable(sql, out errMsg);
                        else
                            dtSQL = DBdb2.RunDataTable(sql, out errMsg);

                        if (dtSQL != null && dtSQL.Rows.Count > 0)
                        {
                            for (int i = 0; i < dtSQL.Rows.Count; i++)
                            {
                                //小数点数
                                num = dtSQL.Rows[i]["小数点数"].ToString();
                                //参数顺序
                                id = int.Parse(dtSQL.Rows[i]["参数顺序"].ToString());
                                //参数ID
                                ParaID = dtSQL.Rows[i]["参数ID"].ToString();

                                sql = dtSQL.Rows[i]["SQL语句"].ToString();

                                if (sql.Contains("&BZ&"))
                                {
                                    sql = sql.Replace("&BZ&", "0");
                                    sql = sql.Replace("&bt&", DateTime.Parse(bTime).ToString("yyyy-MM-dd 0:00:00"));
                                    sql = sql.Replace("&et&", DateTime.Parse(eTime).ToString("yyyy-MM-dd H:mm:ss"));
                                }
                                else if (sql.Contains("&bt&") && sql.Contains("&et&"))
                                {
                                    sql = sql.Replace("&bt&", bTime);
                                    sql = sql.Replace("&et&", DateTime.Parse(eTime).ToString("yyyy-MM-dd H:mm:ss"));
                                }

                                if (rlDBType == "SQL")
                                    obj = DBsql.RunSingle(sql, out errMsg);
                                else
                                    obj = DBdb2.RunSingle(sql, out errMsg);

                                res = "";
                                if (obj != null && obj.ToString() != "")
                                {
                                    if (obj.ToString() != "")
                                        res = obj.ToString();
                                    else
                                        res = "0";
                                }
                                else
                                { res = "0"; }

                                if (id != 0)
                                {
                                    zb[id] = dtSQL.Rows[i]["参数名"].ToString();
                                    un[id] = dtSQL.Rows[i]["单位"].ToString();
                                    lay[id] = dtSQL.Rows[i]["设计值"].ToString();

                                    dv[id] += sh.ShowPoint(res, num) + ',';
                                    dvExcel[id] += res + ',';
                                }

                                if (ParaID != "")
                                {
                                    if (htUn.ContainsKey(ParaID))
                                    {
                                        htUn.Remove(ParaID);
                                        htUn.Add(ParaID, res);
                                    }
                                    else
                                        htUn.Add(ParaID, res);
                                }

                            }
                        }
                        #endregion

                        #region 存储过程

                        sql = "select * from T_sheet_ZsheetPara where 报表名称='" + repName + "' and 班组=0  and 机组=0 and 参数类型='存储过程' and 公式级别=" + gsjb;

                        DataTable dtSP = null;

                        if (rlDBType == "SQL")
                            dtSP = DBsql.RunDataTable(sql, out errMsg);
                        else
                            dtSP = DBdb2.RunDataTable(sql, out errMsg);

                        if (dtSP != null && dtSP.Rows.Count > 0)
                        {
                            for (int i = 0; i < dtSP.Rows.Count; i++)
                            {
                                //小数点数
                                num = dtSP.Rows[i]["小数点数"].ToString();
                                //参数顺序
                                id = int.Parse(dtSP.Rows[i]["参数顺序"].ToString());
                                //参数ID
                                ParaID = dtSP.Rows[i]["参数ID"].ToString();

                                spName = dtSP.Rows[i]["SQL语句"].ToString();

                                string paras = dtSP.Rows[i]["公式参数"].ToString();

                                if (paras != "" && paras != null)
                                    value = pm.RetMonSPPara(paras, htGY, htUn);

                                if (rlDBType == "SQL")
                                    obj = DBsql.RunSingle_SP(spName, dtSP.Rows[i]["ID_KEY"].ToString(), bTime, eTime, "0", paras, value, out errMsg);
                                else
                                    obj = DBdb2.RunSingle_SP(spName, dtSP.Rows[i]["ID_KEY"].ToString(), bTime, eTime, "0", paras, value, out errMsg);

                                if (obj != null && obj.ToString() != "")
                                {
                                    if (obj.ToString() != "")
                                        res = obj.ToString();
                                    else
                                        res = "0";
                                }
                                else
                                { res = "0"; }

                                if (id != 0)
                                {
                                    zb[id] = dtSP.Rows[i]["参数名"].ToString();
                                    un[id] = dtSP.Rows[i]["单位"].ToString();
                                    lay[id] = dtSP.Rows[i]["设计值"].ToString();

                                    dv[id] += sh.ShowPoint(res, num) + ',';
                                    dvExcel[id] += res + ',';
                                }

                                if (ParaID != "")
                                {
                                    if (htUn.ContainsKey(ParaID))
                                    {
                                        htUn.Remove(ParaID);
                                        htUn.Add(ParaID, res);
                                    }
                                    else
                                        htUn.Add(ParaID, res);
                                }
                            }
                        }
                        #endregion

                        #region 其它
                        sql = "select * from T_sheet_ZsheetPara where 报表名称='" + repName + "' and 班组=0 and 机组=0 and 参数类型='其它' and 公式级别=" + gsjb;

                        DataTable dtQT = null;

                        if (rlDBType == "SQL")
                            dtQT = DBsql.RunDataTable(sql, out errMsg);
                        else
                            dtQT = DBdb2.RunDataTable(sql, out errMsg);

                        if (dtQT.Rows.Count > 0 && dtQT != null)
                        {
                            for (int i = 0; i < dtQT.Rows.Count; i++)
                            {
                                //小数点数
                                num = dtQT.Rows[i]["小数点数"].ToString();
                                //参数顺序
                                id = int.Parse(dtQT.Rows[i]["参数顺序"].ToString());
                                //参数ID
                                ParaID = dtQT.Rows[i]["参数ID"].ToString();

                                #region 购网电量
                                if (dtQT.Rows[i]["参数名"].ToString() == "购网电量")
                                {
                                    //string re = um.gwdl(qsrq, jsrq, unit);

                                    //if (dtQT.Rows[i]["显示"].ToString() == "1")
                                    //{
                                    //    id = int.Parse(dtQT.Rows[i]["参数顺序"].ToString());

                                    //    dv[id] += sh.ShowPoint(re.ToString(), num) + ",";

                                    //    dvExcel[id] += sh.ShowPoint(re.ToString(), "-1") + ",";
                                    //}

                                    //if (dtQT.Rows[i]["参数ID"].ToString() != "")
                                    //{
                                    //    id = int.Parse(dtQT.Rows[i]["参数key"].ToString());

                                    //    du[id] += dtQT.Rows[i]["参数ID"].ToString() + "," + re + ";";
                                    //}
                                }
                                #endregion

                                #region 入炉煤低位发热量
                                if (dtQT.Rows[i]["参数名"].ToString() == "入炉煤低位发热量")
                                {
                                    //string rlm = um.rlmdwfrl("值报", DateTime.Parse(qsrq).ToString("yyyy-MM-dd 0:00:00"), jsrq, unit, dtLevBZ.Rows[k]["班组编号"].ToString());

                                    //if (dtQT.Rows[i]["显示"].ToString() == "1")
                                    //{
                                    //    id = int.Parse(dtQT.Rows[i]["参数顺序"].ToString());

                                    //    dv[id] += sh.ShowPoint(rlm, num) + ",";

                                    //    dvExcel[id] += sh.ShowPoint(rlm, "-1") + ",";
                                    //}

                                    //if (dtQT.Rows[i]["参数ID"].ToString() != "")
                                    //{
                                    //    id = int.Parse(dtQT.Rows[i]["参数key"].ToString());

                                    //    //du[id] += dtQT.Rows[i]["参数ID"].ToString() + "," + sh.ShowPoint(rlm, num) + ";";

                                    //    du[id] += dtQT.Rows[i]["参数ID"].ToString() + "," + rlm + ";";
                                    //}
                                }
                                #endregion
                            }
                        }
                        #endregion

                        #region 公式
                        sql = "select * from T_sheet_ZsheetPara where 报表名称='" + repName + "'  and 班组=0  and 机组=0 and 参数类型='公式' and 公式级别=" + gsjb;

                        DataTable dtMon = null;

                        if (rlDBType == "SQL")
                            dtMon = DBsql.RunDataTable(sql, out errMsg);
                        else
                            dtMon = DBdb2.RunDataTable(sql, out errMsg);

                        if (dtMon != null && dtMon.Rows.Count > 0)
                        {
                            for (int i = 0; i < dtMon.Rows.Count; i++)
                            {
                                //小数点数
                                num = dtMon.Rows[i]["小数点数"].ToString();
                                //参数顺序
                                id = int.Parse(dtMon.Rows[i]["参数顺序"].ToString());
                                //参数ID
                                ParaID = dtMon.Rows[i]["参数ID"].ToString();

                                string pMon = dtMon.Rows[i]["公式"].ToString();

                                string paras = dtMon.Rows[i]["公式参数"].ToString();

                                string month = pm.retMonByValPara(htGY, htUn, paras, pMon);

                                if (month != "")
                                {
                                    res = "";
                                    try
                                    { res = StrHelper.Cale(month); }
                                    catch
                                    {
                                        res = "0";
                                        LogHelper.WriteLog(LogHelper.EnLogType.Run, DateTime.Now.ToString("yyyy-MM-dd H:mm:ss") + " 日值 公式 报程序异常: " + pMon + ":" + paras + ":" + month);
                                    }

                                    if (id != 0)
                                    {
                                        zb[id] = dtMon.Rows[i]["参数名"].ToString();
                                        un[id] = dtMon.Rows[i]["单位"].ToString();
                                        lay[id] = dtMon.Rows[i]["设计值"].ToString();

                                        dv[id] += sh.ShowPoint(res, num) + ',';
                                        dvExcel[id] += res + ',';
                                    }

                                    if (ParaID != "")
                                    {
                                        if (htUn.ContainsKey(ParaID))
                                        {
                                            htUn.Remove(ParaID);
                                            htUn.Add(ParaID, res);
                                        }
                                        else
                                            htUn.Add(ParaID, res);
                                    }
                                }
                            }
                        }

                        #endregion
                    }

                    LogHelper.WriteLog(LogHelper.EnLogType.Run, DateTime.Now.ToString("yyyy-MM-dd H:mm:ss") + "---" + repName + "----" + repType + "----全厂数据横向取值结束!");
                }
                #endregion
            }
            else
            {
                #region 单机组班值数据获取

                if (type == "zr")
                    sql = "select 班组编号 from 排班表 where 起始时间 between '" + bTime + "' and '" + eTime + "'";
                else
                    sql = "select 班组编号 from 班组表";

                if (rlDBType == "SQL")
                    dtBZ = DBsql.RunDataTable(sql, out errMsg);
                else if (rlDBType == "DB2")
                    dtBZ = DBdb2.RunDataTable(sql, out errMsg);

                if (dtBZ.Rows.Count > 0)
                {
                    LogHelper.WriteLog(LogHelper.EnLogType.Run, DateTime.Now.ToString("yyyy-MM-dd H:mm:ss") + "---" + repName + "----" + repType + "-----机组" + unit + "----单机组数据取值开始!");

                    for (int j = 0; j < dtBZ.Rows.Count; j++)
                    {
                        bzID = dtBZ.Rows[j]["班组编号"].ToString();

                        BZ += dtBZ.Rows[j]["班组编号"].ToString() + ",";

                        sql = "select * from 排班表 where 起始时间 between '" + bTime + "' and '" + eTime + "' and 班组编号='" + bzID + "'";

                        if (rlDBType == "SQL")
                            dtISPB = DBsql.RunDataTable(sql, out errMsg);
                        else if (rlDBType == "DB2")
                            dtISPB = DBdb2.RunDataTable(sql, out errMsg);

                        if (dtISPB != null && dtISPB.Rows.Count > 0)
                            flag = true;
                        else
                            flag = false;

                        if (flag == false)
                        {
                            #region  非当班班组值获取
                            sql = "select * from T_sheet_ZsheetPara where 报表名称='" + repName + "' and 班组=" + bzID + " and 机组=" + unit;

                            DataTable dtNotPB = null;

                            if (rlDBType == "SQL")
                                dtNotPB = DBsql.RunDataTable(sql, out errMsg);
                            else
                                dtNotPB = DBdb2.RunDataTable(sql, out errMsg);

                            if (dtNotPB != null && dtNotPB.Rows.Count > 0)
                            {
                                for (int i = 0; i < dtNotPB.Rows.Count; i++)
                                {
                                    //小数点数
                                    num = dtNotPB.Rows[i]["小数点数"].ToString();
                                    //参数顺序
                                    id = int.Parse(dtNotPB.Rows[i]["参数顺序"].ToString());
                                    //参数ID
                                    ParaID = dtNotPB.Rows[i]["参数ID"].ToString();

                                    if (id != 0)
                                    {
                                        zb[id] = dtNotPB.Rows[i]["参数名"].ToString();
                                        un[id] = dtNotPB.Rows[i]["单位"].ToString();
                                        lay[id] = dtNotPB.Rows[i]["设计值"].ToString();

                                        dv[id] += "0,";
                                        dvExcel[id] += "0,";
                                    }

                                    if (ParaID != "")
                                    {
                                        if (htUn.ContainsKey(ParaID))
                                        {
                                            htUn.Remove(ParaID);
                                            htUn.Add(ParaID, "0");
                                        }
                                        else
                                            htUn.Add(ParaID, "0");
                                    }
                                }
                            }
                            #endregion
                        }
                        else
                        {
                            #region 当班班值数据获取
                            sql = "SELECT DISTINCT 公式级别 FROM T_sheet_ZsheetPara where 报表名称='" + repName + "' and 班组=" + bzID + " and 机组 =" + unit + " and 公式级别!=0";

                            if (rlDBType == "SQL")
                                dtLel = DBsql.RunDataTable(sql, out errMsg);
                            else if (rlDBType == "DB2")
                                dtLel = DBdb2.RunDataTable(sql, out errMsg);

                            if (dtLel.Rows.Count > 0)
                            {
                                for (int k = 0; k < dtLel.Rows.Count; k++)
                                {
                                    //公式级别
                                    gsjb = dtLel.Rows[k]["公式级别"].ToString();

                                    #region 平均
                                    sql = "select * from T_sheet_ZsheetPara where 报表名称='" + repName + "' and 班组=" + bzID + " and 机组=" + unit + " and 参数类型='平均' and 公式级别=" + gsjb;

                                    DataTable dtAvg = null;

                                    if (rlDBType == "SQL")
                                        dtAvg = DBsql.RunDataTable(sql, out errMsg);
                                    else
                                        dtAvg = DBdb2.RunDataTable(sql, out errMsg);

                                    if (dtAvg != null && dtAvg.Rows.Count > 0)
                                    {
                                        for (int i = 0; i < dtAvg.Rows.Count; i++)
                                        {
                                            //小数点数
                                            num = dtAvg.Rows[i]["小数点数"].ToString();
                                            //参数顺序
                                            id = int.Parse(dtAvg.Rows[i]["参数顺序"].ToString());
                                            //参数ID
                                            ParaID = dtAvg.Rows[i]["参数ID"].ToString();

                                            if (dtAvg.Rows[i]["统计ID"].ToString() != "")
                                                sql = "select 统计值 from " + bName + " where 时间='" + bTime + "' and 机组=" + unit + " and 班组=" + bzID + " and 统计ID ='" + dtAvg.Rows[i]["统计ID"].ToString() + "'";
                                            else
                                                LogHelper.WriteLog(LogHelper.EnLogType.Run, DateTime.Now.ToString("yyyy-MM-dd H:mm:ss") + " 日值 平均 报程序异常: 班组编号 || 统计ID 为空" + sql);

                                            if (rlDBType == "SQL")
                                                objVal = DBsql.RunSingle(sql, out errMsg);
                                            else
                                                objVal = DBdb2.RunSingle(sql, out errMsg);

                                            res = "";
                                            if (objVal != null && objVal != "")
                                            {
                                                if (objVal.ToString() != "")
                                                    res = objVal.ToString();
                                                else
                                                    res = "0";
                                            }
                                            else
                                            { res = "0"; }

                                            if (id != 0)
                                            {
                                                zb[id] = dtAvg.Rows[i]["参数名"].ToString();
                                                un[id] = dtAvg.Rows[i]["单位"].ToString();
                                                lay[id] = dtAvg.Rows[i]["设计值"].ToString();

                                                dv[id] += sh.ShowPoint(res, num) + ',';
                                                dvExcel[id] += res + ',';
                                            }

                                            if (ParaID != "")
                                            {
                                                if (htUn.ContainsKey(ParaID))
                                                {
                                                    htUn.Remove(ParaID);
                                                    htUn.Add(ParaID, res);
                                                }
                                                else
                                                    htUn.Add(ParaID, res);
                                            }
                                        }
                                    }
                                    #endregion

                                    #region 累计
                                    sql = "select * from T_sheet_ZsheetPara where 报表名称='" + repName + "' and 班组=" + bzID + " and 机组=" + unit + " and 参数类型='累计' and 公式级别=" + gsjb;

                                    DataTable dtDiff = null;

                                    if (rlDBType == "SQL")
                                        dtDiff = DBsql.RunDataTable(sql, out errMsg);
                                    else
                                        dtDiff = DBdb2.RunDataTable(sql, out errMsg);

                                    if (dtDiff != null && dtDiff.Rows.Count > 0)
                                    {
                                        for (int i = 0; i < dtDiff.Rows.Count; i++)
                                        {
                                            //小数点数
                                            num = dtDiff.Rows[i]["小数点数"].ToString();
                                            //参数顺序
                                            id = int.Parse(dtDiff.Rows[i]["参数顺序"].ToString());
                                            //参数ID
                                            ParaID = dtDiff.Rows[i]["参数ID"].ToString();

                                            if (dtDiff.Rows[i]["统计ID"].ToString() != "")
                                                sql = "select 统计值 from " + bName + " where 时间='" + bTime + "' and 机组=" + unit + " and 班组=" + bzID + " and 统计ID ='" + dtDiff.Rows[i]["统计ID"].ToString() + "'";
                                            else
                                                LogHelper.WriteLog(LogHelper.EnLogType.Run, DateTime.Now.ToString("yyyy-MM-dd H:mm:ss") + " 日值 平均 报程序异常: 班组编号 || 统计ID 为空" + sql);

                                            if (rlDBType == "SQL")
                                                objVal = DBsql.RunSingle(sql, out errMsg);
                                            else
                                                objVal = DBdb2.RunSingle(sql, out errMsg);

                                            res = "";
                                            if (objVal != null && objVal != "")
                                            {
                                                if (objVal.ToString() != "")
                                                    res = objVal.ToString();
                                                else
                                                    res = "0";
                                            }
                                            else
                                            { res = "0"; }

                                            if (id != 0)
                                            {
                                                zb[id] = dtDiff.Rows[i]["参数名"].ToString();
                                                un[id] = dtDiff.Rows[i]["单位"].ToString();
                                                lay[id] = dtDiff.Rows[i]["设计值"].ToString();

                                                dv[id] += sh.ShowPoint(res, num) + ',';
                                                dvExcel[id] += res + ',';
                                            }

                                            if (ParaID != "")
                                            {
                                                if (htUn.ContainsKey(ParaID))
                                                {
                                                    htUn.Remove(ParaID);
                                                    htUn.Add(ParaID, res);
                                                }
                                                else
                                                    htUn.Add(ParaID, res);
                                            }
                                        }
                                    }
                                    #endregion

                                    //LogHelper.WriteLog(LogHelper.EnLogType.Run, DateTime.Now.ToString("yyyy-MM-dd H:mm:ss") + "-----------电量模块开始-----------" + repName + "---***************************----机组" + unit);
                                    #region 电量
                                    sql = "select * from T_sheet_ZsheetPara where 报表名称='" + repName + "' and 班组=" + bzID + "  and 机组=" + unit + " and 参数类型='电量' and 公式级别=" + gsjb + " order by ID_KEY asc";

                                    DataTable dtDL = null;

                                    if (rlDBType == "SQL")
                                        dtDL = DBsql.RunDataTable(sql, out errMsg);
                                    else
                                        dtDL = DBdb2.RunDataTable(sql, out errMsg);

                                    if (dtDL.Rows.Count > 0 && dtDL != null)
                                    {
                                        for (int i = 0; i < dtDL.Rows.Count; i++)
                                        {
                                            dlID = dtDL.Rows[i]["电量点"].ToString();
                                            //小数点数
                                            num = dtDL.Rows[i]["小数点数"].ToString();
                                            //参数顺序
                                            id = int.Parse(dtDL.Rows[i]["参数顺序"].ToString());
                                            //参数ID
                                            ParaID = dtDL.Rows[i]["参数ID"].ToString();

                                            try
                                            {
                                                //电量
                                                double dl = 0;
                                                double sdl = 0;
                                                double edl = 0;

                                                if (dlID != "")
                                                {
                                                    sql = " select * from 排班表 where 起始时间 between '" + bTime + "' and '" + eTime + "' and 班组编号='" + bzID + "' union select * from 排班表 where 结束时间 between '" + bTime + "' and '" + eTime + "' and 班组编号='" + bzID + "'";

                                                    DataTable dtPB = null;

                                                    if (rlDBType == "SQL")
                                                        dtPB = DBsql.RunDataTable(sql, out errMsg);
                                                    else
                                                        dtPB = DBdb2.RunDataTable(sql, out errMsg);

                                                    mon = "";

                                                    string startTime = "";
                                                    string endTime = "";
                                                    if (dtPB != null && dtPB.Rows.Count > 0)
                                                    {
                                                        string monDL = "0+";

                                                        for (int q = 0; q < dtPB.Rows.Count; q++)
                                                        {
                                                            startTime += "'" + dtPB.Rows[q]["起始时间"].ToString().Trim() + "',";
                                                            endTime += "'" + dtPB.Rows[q]["结束时间"].ToString().Trim() + "',";
                                                        }
                                                    }

                                                    startTime = startTime.Substring(0, startTime.Length - 1);
                                                    endTime = endTime.Substring(0, endTime.Length - 1);


                                                    //表码值
                                                    object sbm = null;
                                                    object ebm = null;
                                                    string sqlsbm = "SELECT sum(表码值) as 表码 FROM ADMINISTRATOR.设备表码数据表 where  设备ID='" + dlID + "'  and 时间 in(" + startTime + ")";
                                                    string sqlebm = "SELECT sum(表码值) as 表码 FROM ADMINISTRATOR.设备表码数据表 where  设备ID='" + dlID + "'  and 时间 in(" + endTime + ")";
                                                    //换表表码
                                                    object hbsbm = null;
                                                    object hbebm = null;
                                                    string sqlhbsbm = "SELECT sum(表码值) as 表码 FROM ADMINISTRATOR.设备换表起码数据表 where  设备ID='" + dlID + "'  and 时间 in(" + startTime + ")";
                                                    string sqlhbebm = "SELECT sum(表码值) as 表码 FROM ADMINISTRATOR.设备换表起码数据表 where  设备ID='" + dlID + "'  and 时间 in(" + endTime + ")";

                                                    //倍率
                                                    string sqlbl = "SELECT 倍率 FROM ADMINISTRATOR.设备倍率表 where 设备ID='" + dlID + "'";
                                                    double bl = 1;
                                                    //表码上限
                                                    string sqlbmsx = "SELECT 表码上限 FROM ADMINISTRATOR.设备表码上限表 where 设备ID='" + dlID + "'";
                                                    double sx = 0;

                                                    if (rlDBType == "SQL")
                                                    {
                                                        sbm = DBsql.RunSingle(sqlsbm, out errMsg);
                                                        ebm = DBsql.RunSingle(sqlebm, out errMsg);
                                                        hbsbm = DBsql.RunSingle(sqlhbsbm, out errMsg);
                                                        hbebm = DBsql.RunSingle(sqlhbebm, out errMsg);
                                                        bl = Convert.ToDouble(DBsql.RunSingle(sqlbl, out errMsg).ToString());
                                                        sx = Convert.ToDouble(DBsql.RunSingle(sqlbmsx, out errMsg).ToString());
                                                    }
                                                    else
                                                    {
                                                        sbm = DBdb2.RunSingle(sqlsbm, out errMsg);
                                                        ebm = DBdb2.RunSingle(sqlebm, out errMsg);
                                                        hbsbm = DBdb2.RunSingle(sqlhbsbm, out errMsg);
                                                        hbebm = DBdb2.RunSingle(sqlhbebm, out errMsg);
                                                        bl = Convert.ToDouble(DBdb2.RunSingle(sqlbl, out errMsg).ToString());
                                                        sx = Convert.ToDouble(DBdb2.RunSingle(sqlbmsx, out errMsg).ToString());
                                                    }

                                                    if (sbm != null)
                                                        if (hbsbm != null)
                                                            sdl = Convert.ToDouble(sbm.ToString()) + Convert.ToDouble(hbsbm.ToString());
                                                        else
                                                            sdl = Convert.ToDouble(sbm.ToString());
                                                    if (ebm != null)
                                                        if (hbebm != null)
                                                            edl = Convert.ToDouble(ebm.ToString()) + Convert.ToDouble(hbebm.ToString());
                                                        else
                                                            edl = Convert.ToDouble(ebm.ToString());

                                                    if (edl - sdl >= 0)
                                                    {
                                                        dl = (edl - sdl) * bl;
                                                    }
                                                    else
                                                    {
                                                        dl = (edl - sdl + sx) * bl;
                                                    }
                                                }

                                                if (id != 0)
                                                {
                                                    zb[id] = dtDL.Rows[i]["参数名"].ToString();
                                                    un[id] = dtDL.Rows[i]["单位"].ToString();
                                                    lay[id] = dtDL.Rows[i]["设计值"].ToString();

                                                    dv[id] += sh.ShowPoint(dl.ToString(), num) + ',';
                                                    dvExcel[id] += dl + ',';
                                                }

                                                if (ParaID != "")
                                                {
                                                    if (htUn.ContainsKey(ParaID))
                                                    {
                                                        htUn.Remove(ParaID);
                                                        htUn.Add(ParaID, dl);
                                                    }
                                                    else
                                                        htUn.Add(ParaID, dl);
                                                }
                                            }
                                            catch (Exception ce)
                                            {

                                            }
                                        }
                                    }

                                    #endregion

                                    //LogHelper.WriteLog(LogHelper.EnLogType.Run, DateTime.Now.ToString("yyyy-MM-dd H:mm:ss") + "-----------电量模块结束-----------" + repName + "---****************************---机组" + unit);

                                    #region SQL

                                    sql = "select * from T_sheet_ZsheetPara where 报表名称='" + repName + "'  and 班组=" + bzID + "  and 机组=" + unit + " and 参数类型='SQL' and 公式级别=" + gsjb;

                                    DataTable dtSQL = null;

                                    if (rlDBType == "SQL")
                                        dtSQL = DBsql.RunDataTable(sql, out errMsg);
                                    else
                                        dtSQL = DBdb2.RunDataTable(sql, out errMsg);

                                    if (dtSQL != null && dtSQL.Rows.Count > 0)
                                    {
                                        for (int i = 0; i < dtSQL.Rows.Count; i++)
                                        {
                                            //小数点数
                                            num = dtSQL.Rows[i]["小数点数"].ToString();
                                            //参数顺序
                                            id = int.Parse(dtSQL.Rows[i]["参数顺序"].ToString());
                                            //参数ID
                                            ParaID = dtSQL.Rows[i]["参数ID"].ToString();

                                            sql = dtSQL.Rows[i]["SQL语句"].ToString();

                                            if (sql.Contains("&BZ&"))
                                            {
                                                sql = sql.Replace("&BZ&", bzID);
                                                sql = sql.Replace("&bt&", DateTime.Parse(bTime).ToString("yyyy-MM-dd 0:00:00"));
                                                sql = sql.Replace("&et&", DateTime.Parse(eTime).ToString("yyyy-MM-dd H:mm:ss"));
                                            }
                                            else if (sql.Contains("&bt&") && sql.Contains("&et&"))
                                            {
                                                sql = sql.Replace("&bt&", bTime);
                                                sql = sql.Replace("&et&", DateTime.Parse(eTime).ToString("yyyy-MM-dd H:mm:ss"));
                                            }

                                            if (rlDBType == "SQL")
                                                obj = DBsql.RunSingle(sql, out errMsg);
                                            else
                                                obj = DBdb2.RunSingle(sql, out errMsg);

                                            res = "";
                                            if (obj != null && obj.ToString() != "")
                                            {
                                                if (obj.ToString() != "")
                                                    res = obj.ToString();
                                                else
                                                    res = "0";
                                            }
                                            else
                                            { res = "0"; }

                                            if (id != 0)
                                            {
                                                zb[id] = dtSQL.Rows[i]["参数名"].ToString();
                                                un[id] = dtSQL.Rows[i]["单位"].ToString();
                                                lay[id] = dtSQL.Rows[i]["设计值"].ToString();

                                                dv[id] += sh.ShowPoint(res, num) + ',';
                                                dvExcel[id] += res + ',';
                                            }

                                            if (ParaID != "")
                                            {
                                                if (htUn.ContainsKey(ParaID))
                                                {
                                                    htUn.Remove(ParaID);
                                                    htUn.Add(ParaID, res);
                                                }
                                                else
                                                    htUn.Add(ParaID, res);
                                            }

                                        }
                                    }
                                    #endregion

                                    //LogHelper.WriteLog(LogHelper.EnLogType.Run, DateTime.Now.ToString("yyyy-MM-dd H:mm:ss") + "-----------存储过程开始-----------" + repName + "---***************************----机组" + unit);

                                    #region 存储过程
                                    sql = "select * from T_sheet_ZsheetPara where 报表名称='" + repName + "' and 班组=" + bzID + "  and 机组=" + unit + " and 参数类型='存储过程' and 公式级别=" + gsjb;

                                    DataTable dtSP = null;

                                    if (rlDBType == "SQL")
                                        dtSP = DBsql.RunDataTable(sql, out errMsg);
                                    else
                                        dtSP = DBdb2.RunDataTable(sql, out errMsg);

                                    if (dtSP != null && dtSP.Rows.Count > 0)
                                    {
                                        for (int i = 0; i < dtSP.Rows.Count; i++)
                                        {
                                            //小数点数
                                            num = dtSP.Rows[i]["小数点数"].ToString();
                                            //参数顺序
                                            id = int.Parse(dtSP.Rows[i]["参数顺序"].ToString());
                                            //参数ID
                                            ParaID = dtSP.Rows[i]["参数ID"].ToString();

                                            spName = dtSP.Rows[i]["SQL语句"].ToString();

                                            string paras = dtSP.Rows[i]["公式参数"].ToString();

                                            if (paras != "" && paras != null)
                                                value = pm.RetMonSPPara(paras, htGY, htUn);


                                            if (rlDBType == "SQL")
                                                obj = DBsql.RunSingle_SP(spName, dtSP.Rows[i]["ID_KEY"].ToString(), bTime, eTime, bzID, paras, value, out errMsg);
                                            else
                                                obj = DBdb2.RunSingle_SP(spName, dtSP.Rows[i]["ID_KEY"].ToString(), bTime, eTime, bzID, paras, value, out errMsg);

                                            if (obj != null && obj.ToString() != "")
                                            {
                                                if (obj.ToString() != "")
                                                    res = obj.ToString();
                                                else
                                                    res = "0";
                                            }
                                            else
                                            { res = "0"; }

                                            if (id != 0)
                                            {
                                                zb[id] = dtSP.Rows[i]["参数名"].ToString();
                                                un[id] = dtSP.Rows[i]["单位"].ToString();
                                                lay[id] = dtSP.Rows[i]["设计值"].ToString();

                                                dv[id] += sh.ShowPoint(res, num) + ',';
                                                dvExcel[id] += res + ',';
                                            }

                                            if (ParaID != "")
                                            {
                                                if (htUn.ContainsKey(ParaID))
                                                {
                                                    htUn.Remove(ParaID);
                                                    htUn.Add(ParaID, res);
                                                }
                                                else
                                                    htUn.Add(ParaID, res);
                                            }
                                        }
                                    }
                                    #endregion

                                    //LogHelper.WriteLog(LogHelper.EnLogType.Run, DateTime.Now.ToString("yyyy-MM-dd H:mm:ss") + "-----------存储过程块开始-----------" + repName + "---***************************----机组" + unit);

                                    #region 其它
                                    sql = "select * from T_sheet_ZsheetPara where 报表名称='" + repName + "' and 班组=" + bzID + " and 机组=" + unit + " and 参数类型='其它' and 公式级别=" + gsjb;

                                    DataTable dtQT = null;

                                    if (rlDBType == "SQL")
                                        dtQT = DBsql.RunDataTable(sql, out errMsg);
                                    else
                                        dtQT = DBdb2.RunDataTable(sql, out errMsg);

                                    if (dtQT.Rows.Count > 0 && dtQT != null)
                                    {
                                        for (int i = 0; i < dtQT.Rows.Count; i++)
                                        {
                                            //小数点数
                                            num = dtQT.Rows[i]["小数点数"].ToString();
                                            //参数顺序
                                            id = int.Parse(dtQT.Rows[i]["参数顺序"].ToString());
                                            //参数ID
                                            ParaID = dtQT.Rows[i]["参数ID"].ToString();

                                            #region 购网电量
                                            if (dtQT.Rows[i]["参数名"].ToString() == "购网电量")
                                            {
                                                //string re = um.gwdl(qsrq, jsrq, unit);

                                                //if (dtQT.Rows[i]["显示"].ToString() == "1")
                                                //{
                                                //    id = int.Parse(dtQT.Rows[i]["参数顺序"].ToString());

                                                //    dv[id] += sh.ShowPoint(re.ToString(), num) + ",";

                                                //    dvExcel[id] += sh.ShowPoint(re.ToString(), "-1") + ",";
                                                //}

                                                //if (dtQT.Rows[i]["参数ID"].ToString() != "")
                                                //{
                                                //    id = int.Parse(dtQT.Rows[i]["参数key"].ToString());

                                                //    du[id] += dtQT.Rows[i]["参数ID"].ToString() + "," + re + ";";
                                                //}
                                            }
                                            #endregion

                                            #region 入炉煤低位发热量
                                            if (dtQT.Rows[i]["参数名"].ToString() == "入炉煤低位发热量")
                                            {
                                                //string rlm = um.rlmdwfrl("值报", DateTime.Parse(qsrq).ToString("yyyy-MM-dd 0:00:00"), jsrq, unit, dtLevBZ.Rows[k]["班组编号"].ToString());

                                                //if (dtQT.Rows[i]["显示"].ToString() == "1")
                                                //{
                                                //    id = int.Parse(dtQT.Rows[i]["参数顺序"].ToString());

                                                //    dv[id] += sh.ShowPoint(rlm, num) + ",";

                                                //    dvExcel[id] += sh.ShowPoint(rlm, "-1") + ",";
                                                //}

                                                //if (dtQT.Rows[i]["参数ID"].ToString() != "")
                                                //{
                                                //    id = int.Parse(dtQT.Rows[i]["参数key"].ToString());

                                                //    //du[id] += dtQT.Rows[i]["参数ID"].ToString() + "," + sh.ShowPoint(rlm, num) + ";";

                                                //    du[id] += dtQT.Rows[i]["参数ID"].ToString() + "," + rlm + ";";
                                                //}
                                            }
                                            #endregion
                                        }
                                    }
                                    #endregion

                                    #region 公式
                                    sql = "select * from T_sheet_ZsheetPara where 报表名称='" + repName + "'  and 班组=" + bzID + "  and 机组=" + unit + " and 参数类型='公式' and 公式级别=" + gsjb;

                                    DataTable dtMon = null;

                                    if (rlDBType == "SQL")
                                        dtMon = DBsql.RunDataTable(sql, out errMsg);
                                    else
                                        dtMon = DBdb2.RunDataTable(sql, out errMsg);

                                    if (dtMon != null && dtMon.Rows.Count > 0)
                                    {
                                        for (int i = 0; i < dtMon.Rows.Count; i++)
                                        {
                                            //小数点数
                                            num = dtMon.Rows[i]["小数点数"].ToString();
                                            //参数顺序
                                            id = int.Parse(dtMon.Rows[i]["参数顺序"].ToString());
                                            //参数ID
                                            ParaID = dtMon.Rows[i]["参数ID"].ToString();

                                            string pMon = dtMon.Rows[i]["公式"].ToString();

                                            string paras = dtMon.Rows[i]["公式参数"].ToString();

                                            string month = pm.retMonByValPara(htGY, htUn, paras, pMon);

                                            if (month != "")
                                            {
                                                res = "";
                                                try
                                                { res = StrHelper.Cale(month); }
                                                catch
                                                {
                                                    res = "0";
                                                    LogHelper.WriteLog(LogHelper.EnLogType.Run, DateTime.Now.ToString("yyyy-MM-dd H:mm:ss") + " 日值 公式 报程序异常: " + pMon + ":" + paras + ":" + month);
                                                }

                                                if (id != 0)
                                                {
                                                    zb[id] = dtMon.Rows[i]["参数名"].ToString();
                                                    un[id] = dtMon.Rows[i]["单位"].ToString();
                                                    lay[id] = dtMon.Rows[i]["设计值"].ToString();

                                                    dv[id] += sh.ShowPoint(res, num) + ',';
                                                    dvExcel[id] += res + ',';
                                                }

                                                if (ParaID != "")
                                                {
                                                    if (htUn.ContainsKey(ParaID))
                                                    {
                                                        htUn.Remove(ParaID);
                                                        htUn.Add(ParaID, res);
                                                    }
                                                    else
                                                        htUn.Add(ParaID, res);
                                                }
                                            }
                                        }
                                    }

                                    #endregion
                                }
                            }
                            #endregion
                        }
                    }

                    LogHelper.WriteLog(LogHelper.EnLogType.Run, DateTime.Now.ToString("yyyy-MM-dd H:mm:ss") + "---" + repName + "----" + repType + "-----机组" + unit + "----单机组数据取值开始!");
                }
                #endregion

                #region 横向计算

                sql = "SELECT DISTINCT 公式级别 FROM T_sheet_ZsheetPara where 报表名称='" + repName + "' and 班组=0 and 机组 =" + unit + " and 公式级别!=0";

                if (rlDBType == "SQL")
                    dtLel = DBsql.RunDataTable(sql, out errMsg);
                else if (rlDBType == "DB2")
                    dtLel = DBdb2.RunDataTable(sql, out errMsg);

                if (dtLel.Rows.Count > 0)
                {
                    LogHelper.WriteLog(LogHelper.EnLogType.Run, DateTime.Now.ToString("yyyy-MM-dd H:mm:ss") + "---" + repName + "----" + repType + "----全厂数据横向计算取值开始!");

                    for (int k = 0; k < dtLel.Rows.Count; k++)
                    {
                        //公式级别
                        gsjb = dtLel.Rows[k]["公式级别"].ToString();

                        #region 平均
                        sql = "select * from T_sheet_ZsheetPara where 报表名称='" + repName + "' and 班组=0 and 机组 =" + unit + " and 参数类型='平均' and 公式级别=" + gsjb;

                        DataTable dtAvg = null;

                        if (rlDBType == "SQL")
                            dtAvg = DBsql.RunDataTable(sql, out errMsg);
                        else
                            dtAvg = DBdb2.RunDataTable(sql, out errMsg);

                        if (dtAvg != null && dtAvg.Rows.Count > 0)
                        {
                            for (int i = 0; i < dtAvg.Rows.Count; i++)
                            {
                                //小数点数
                                num = dtAvg.Rows[i]["小数点数"].ToString();
                                //参数顺序
                                id = int.Parse(dtAvg.Rows[i]["参数顺序"].ToString());
                                //参数ID
                                ParaID = dtAvg.Rows[i]["参数ID"].ToString();

                                if (dtAvg.Rows[i]["统计ID"].ToString() != "")
                                    sql = "select 统计值 from " + bName + " where 时间='" + bTime + "' and 机组 =" + unit + " and 班组=0 and 统计ID ='" + dtAvg.Rows[i]["统计ID"].ToString() + "'";
                                else
                                    LogHelper.WriteLog(LogHelper.EnLogType.Run, DateTime.Now.ToString("yyyy-MM-dd H:mm:ss") + " 日值 平均 报程序异常: 班组编号 || 统计ID 为空" + sql);

                                if (rlDBType == "SQL")
                                    objVal = DBsql.RunSingle(sql, out errMsg);
                                else
                                    objVal = DBdb2.RunSingle(sql, out errMsg);

                                res = "";
                                if (objVal != null && objVal != "")
                                {
                                    if (objVal.ToString() != "")
                                        res = objVal.ToString();
                                    else
                                        res = "0";
                                }
                                else
                                { res = "0"; }

                                if (id != 0)
                                {
                                    zb[id] = dtAvg.Rows[i]["参数名"].ToString();
                                    un[id] = dtAvg.Rows[i]["单位"].ToString();
                                    lay[id] = dtAvg.Rows[i]["设计值"].ToString();

                                    dv[id] += sh.ShowPoint(res, num) + ',';
                                    dvExcel[id] += res + ',';
                                }

                                if (ParaID != "")
                                {
                                    if (htUn.ContainsKey(ParaID))
                                    {
                                        htUn.Remove(ParaID);
                                        htUn.Add(ParaID, res);
                                    }
                                    else
                                        htUn.Add(ParaID, res);
                                }
                            }
                        }
                        #endregion

                        #region 累计
                        sql = "select * from T_sheet_ZsheetPara where 报表名称='" + repName + "' and 班组=0 and 机组 =" + unit + " and 参数类型='累计' and 公式级别=" + gsjb;

                        DataTable dtDiff = null;

                        if (rlDBType == "SQL")
                            dtDiff = DBsql.RunDataTable(sql, out errMsg);
                        else
                            dtDiff = DBdb2.RunDataTable(sql, out errMsg);

                        if (dtDiff != null && dtDiff.Rows.Count > 0)
                        {
                            for (int i = 0; i < dtDiff.Rows.Count; i++)
                            {
                                //小数点数
                                num = dtDiff.Rows[i]["小数点数"].ToString();
                                //参数顺序
                                id = int.Parse(dtDiff.Rows[i]["参数顺序"].ToString());
                                //参数ID
                                ParaID = dtDiff.Rows[i]["参数ID"].ToString();

                                if (dtDiff.Rows[i]["统计ID"].ToString() != "")
                                    sql = "select 统计值 from " + bName + " where 时间='" + bTime + "' and 机组 =" + unit + " and 班组=0 and 统计ID ='" + dtDiff.Rows[i]["统计ID"].ToString() + "'";
                                else
                                    LogHelper.WriteLog(LogHelper.EnLogType.Run, DateTime.Now.ToString("yyyy-MM-dd H:mm:ss") + " 日值 平均 报程序异常: 班组编号 || 统计ID 为空" + sql);

                                if (rlDBType == "SQL")
                                    objVal = DBsql.RunSingle(sql, out errMsg);
                                else
                                    objVal = DBdb2.RunSingle(sql, out errMsg);

                                res = "";
                                if (objVal != null && objVal != "")
                                {
                                    if (objVal.ToString() != "")
                                        res = objVal.ToString();
                                    else
                                        res = "0";
                                }
                                else
                                { res = "0"; }

                                if (id != 0)
                                {
                                    zb[id] = dtDiff.Rows[i]["参数名"].ToString();
                                    un[id] = dtDiff.Rows[i]["单位"].ToString();
                                    lay[id] = dtDiff.Rows[i]["设计值"].ToString();

                                    dv[id] += sh.ShowPoint(res, num) + ',';
                                    dvExcel[id] += res + ',';
                                }

                                if (ParaID != "")
                                {
                                    if (htUn.ContainsKey(ParaID))
                                    {
                                        htUn.Remove(ParaID);
                                        htUn.Add(ParaID, res);
                                    }
                                    else
                                        htUn.Add(ParaID, res);
                                }
                            }
                        }
                        #endregion

                        #region 电量
                        sql = "select * from T_sheet_ZsheetPara where 报表名称='" + repName + "' and 班组=0  and 机组 =" + unit + " and 参数类型='电量' and 公式级别=" + gsjb;

                        DataTable dtDL = null;

                        if (rlDBType == "SQL")
                            dtDL = DBsql.RunDataTable(sql, out errMsg);
                        else
                            dtDL = DBdb2.RunDataTable(sql, out errMsg);

                        if (dtDL.Rows.Count > 0 && dtDL != null)
                        {
                            for (int i = 0; i < dtDL.Rows.Count; i++)
                            {
                                dlID = dtDL.Rows[i]["电量点"].ToString();
                                //小数点数
                                num = dtDL.Rows[i]["小数点数"].ToString();
                                //参数顺序
                                id = int.Parse(dtDL.Rows[i]["参数顺序"].ToString());
                                //参数ID
                                ParaID = dtDL.Rows[i]["参数ID"].ToString();

                                sql = " select * from 排班表 where 起始时间 between '" + bTime + "' and '" + eTime + "' and 班组编号=0 union select * from 排班表 where 结束时间 between '" + bTime + "' and '" + eTime + "' and 班组编号=0";

                                DataTable dtPB = null;

                                if (rlDBType == "SQL")
                                    dtPB = DBsql.RunDataTable(sql, out errMsg);
                                else
                                    dtPB = DBdb2.RunDataTable(sql, out errMsg);

                                mon = "";

                                if (dtPB != null && dtPB.Rows.Count > 0)
                                {
                                    string monDL = "0+";

                                    for (int q = 0; q < dtPB.Rows.Count; q++)
                                    {
                                        string qt = dtPB.Rows[q]["起始时间"].ToString();
                                        string jt = dtPB.Rows[q]["结束时间"].ToString();

                                        drvA = double.Parse(pc.GetPower(drvA, dlID, DateTime.Parse(qt).ToString("yyyy-MM-dd H:00:00"), DateTime.Parse(jt).AddSeconds(+1).ToString("yyyy-MM-dd H:00:00"), bm).ToString());

                                        monDL += drvA.ToString() + "+";
                                    }
                                    mon = monDL.TrimEnd('+');

                                    if (dtDL.Rows[i]["公式"].ToString() != "")
                                        mon = "(" + mon + ")" + dtDL.Rows[i]["公式"].ToString();
                                }

                                res = "";
                                try
                                { res = StrHelper.Cale(mon); }
                                catch
                                { res = "0"; }

                                if (id != 0)
                                {
                                    zb[id] = dtDL.Rows[i]["参数名"].ToString();
                                    un[id] = dtDL.Rows[i]["单位"].ToString();
                                    lay[id] = dtDL.Rows[i]["设计值"].ToString();

                                    dv[id] += sh.ShowPoint(res, num) + ',';
                                    dvExcel[id] += res + ',';
                                }

                                if (ParaID != "")
                                {
                                    if (htUn.ContainsKey(ParaID))
                                    {
                                        htUn.Remove(ParaID);
                                        htUn.Add(ParaID, res);
                                    }
                                    else
                                        htUn.Add(ParaID, res);
                                }
                            }
                        }

                        #endregion

                        #region SQL

                        sql = "select * from T_sheet_ZsheetPara where 报表名称='" + repName + "'  and 班组=0  and 机组 =" + unit + " and 参数类型='SQL' and 公式级别=" + gsjb;

                        DataTable dtSQL = null;

                        if (rlDBType == "SQL")
                            dtSQL = DBsql.RunDataTable(sql, out errMsg);
                        else
                            dtSQL = DBdb2.RunDataTable(sql, out errMsg);

                        if (dtSQL != null && dtSQL.Rows.Count > 0)
                        {
                            for (int i = 0; i < dtSQL.Rows.Count; i++)
                            {
                                //小数点数
                                num = dtSQL.Rows[i]["小数点数"].ToString();
                                //参数顺序
                                id = int.Parse(dtSQL.Rows[i]["参数顺序"].ToString());
                                //参数ID
                                ParaID = dtSQL.Rows[i]["参数ID"].ToString();

                                sql = dtSQL.Rows[i]["SQL语句"].ToString();

                                if (sql.Contains("&BZ&"))
                                {
                                    sql = sql.Replace("&BZ&", "0");
                                    sql = sql.Replace("&bt&", DateTime.Parse(bTime).ToString("yyyy-MM-dd 0:00:00"));
                                    sql = sql.Replace("&et&", DateTime.Parse(eTime).ToString("yyyy-MM-dd H:mm:ss"));
                                }
                                else if (sql.Contains("&bt&") && sql.Contains("&et&"))
                                {
                                    sql = sql.Replace("&bt&", bTime);
                                    sql = sql.Replace("&et&", DateTime.Parse(eTime).ToString("yyyy-MM-dd H:mm:ss"));
                                }

                                if (rlDBType == "SQL")
                                    obj = DBsql.RunSingle(sql, out errMsg);
                                else
                                    obj = DBdb2.RunSingle(sql, out errMsg);

                                res = "";
                                if (obj != null && obj.ToString() != "")
                                {
                                    if (obj.ToString() != "")
                                        res = obj.ToString();
                                    else
                                        res = "0";
                                }
                                else
                                { res = "0"; }

                                if (id != 0)
                                {
                                    zb[id] = dtSQL.Rows[i]["参数名"].ToString();
                                    un[id] = dtSQL.Rows[i]["单位"].ToString();
                                    lay[id] = dtSQL.Rows[i]["设计值"].ToString();

                                    dv[id] += sh.ShowPoint(res, num) + ',';
                                    dvExcel[id] += res + ',';
                                }

                                if (ParaID != "")
                                {
                                    if (htUn.ContainsKey(ParaID))
                                    {
                                        htUn.Remove(ParaID);
                                        htUn.Add(ParaID, res);
                                    }
                                    else
                                        htUn.Add(ParaID, res);
                                }

                            }
                        }
                        #endregion

                        #region 存储过程

                        sql = "select * from T_sheet_ZsheetPara where 报表名称='" + repName + "' and 班组=0  and 机组 =" + unit + " and 参数类型='存储过程' and 公式级别=" + gsjb;

                        DataTable dtSP = null;

                        if (rlDBType == "SQL")
                            dtSP = DBsql.RunDataTable(sql, out errMsg);
                        else
                            dtSP = DBdb2.RunDataTable(sql, out errMsg);

                        if (dtSP != null && dtSP.Rows.Count > 0)
                        {
                            for (int i = 0; i < dtSP.Rows.Count; i++)
                            {
                                //小数点数
                                num = dtSP.Rows[i]["小数点数"].ToString();
                                //参数顺序
                                id = int.Parse(dtSP.Rows[i]["参数顺序"].ToString());
                                //参数ID
                                ParaID = dtSP.Rows[i]["参数ID"].ToString();

                                spName = dtSP.Rows[i]["SQL语句"].ToString();

                                string paras = dtSP.Rows[i]["公式参数"].ToString();

                                if (paras != "" && paras != null)
                                    value = pm.RetMonSPPara(paras, htGY, htUn);


                                if (rlDBType == "SQL")
                                    obj = DBsql.RunSingle_SP(spName, dtSP.Rows[i]["ID_KEY"].ToString(), bTime, eTime, "0", paras, value, out errMsg);
                                else
                                    obj = DBdb2.RunSingle_SP(spName, dtSP.Rows[i]["ID_KEY"].ToString(), bTime, eTime, "'2'", paras, value, out errMsg);

                                if (obj != null && obj.ToString() != "")
                                {
                                    if (obj.ToString() != "")
                                        res = obj.ToString();
                                    else
                                        res = "0";
                                }
                                else
                                { res = "0"; }

                                if (id != 0)
                                {
                                    zb[id] = dtSP.Rows[i]["参数名"].ToString();
                                    un[id] = dtSP.Rows[i]["单位"].ToString();
                                    lay[id] = dtSP.Rows[i]["设计值"].ToString();

                                    dv[id] += sh.ShowPoint(res, num) + ',';
                                    dvExcel[id] += res + ',';
                                }

                                if (ParaID != "")
                                {
                                    if (htUn.ContainsKey(ParaID))
                                    {
                                        htUn.Remove(ParaID);
                                        htUn.Add(ParaID, res);
                                    }
                                    else
                                        htUn.Add(ParaID, res);
                                }
                            }
                        }
                        #endregion

                        #region 其它
                        sql = "select * from T_sheet_ZsheetPara where 报表名称='" + repName + "' and 班组=0 and 机组 =" + unit + " and 参数类型='其它' and 公式级别=" + gsjb;

                        DataTable dtQT = null;

                        if (rlDBType == "SQL")
                            dtQT = DBsql.RunDataTable(sql, out errMsg);
                        else
                            dtQT = DBdb2.RunDataTable(sql, out errMsg);

                        if (dtQT.Rows.Count > 0 && dtQT != null)
                        {
                            for (int i = 0; i < dtQT.Rows.Count; i++)
                            {
                                //小数点数
                                num = dtQT.Rows[i]["小数点数"].ToString();
                                //参数顺序
                                id = int.Parse(dtQT.Rows[i]["参数顺序"].ToString());
                                //参数ID
                                ParaID = dtQT.Rows[i]["参数ID"].ToString();

                                #region 购网电量
                                if (dtQT.Rows[i]["参数名"].ToString() == "购网电量")
                                {
                                    //string re = um.gwdl(qsrq, jsrq, unit);

                                    //if (dtQT.Rows[i]["显示"].ToString() == "1")
                                    //{
                                    //    id = int.Parse(dtQT.Rows[i]["参数顺序"].ToString());

                                    //    dv[id] += sh.ShowPoint(re.ToString(), num) + ",";

                                    //    dvExcel[id] += sh.ShowPoint(re.ToString(), "-1") + ",";
                                    //}

                                    //if (dtQT.Rows[i]["参数ID"].ToString() != "")
                                    //{
                                    //    id = int.Parse(dtQT.Rows[i]["参数key"].ToString());

                                    //    du[id] += dtQT.Rows[i]["参数ID"].ToString() + "," + re + ";";
                                    //}
                                }
                                #endregion

                                #region 入炉煤低位发热量
                                if (dtQT.Rows[i]["参数名"].ToString() == "入炉煤低位发热量")
                                {
                                    //string rlm = um.rlmdwfrl("值报", DateTime.Parse(qsrq).ToString("yyyy-MM-dd 0:00:00"), jsrq, unit, dtLevBZ.Rows[k]["班组编号"].ToString());

                                    //if (dtQT.Rows[i]["显示"].ToString() == "1")
                                    //{
                                    //    id = int.Parse(dtQT.Rows[i]["参数顺序"].ToString());

                                    //    dv[id] += sh.ShowPoint(rlm, num) + ",";

                                    //    dvExcel[id] += sh.ShowPoint(rlm, "-1") + ",";
                                    //}

                                    //if (dtQT.Rows[i]["参数ID"].ToString() != "")
                                    //{
                                    //    id = int.Parse(dtQT.Rows[i]["参数key"].ToString());

                                    //    //du[id] += dtQT.Rows[i]["参数ID"].ToString() + "," + sh.ShowPoint(rlm, num) + ";";

                                    //    du[id] += dtQT.Rows[i]["参数ID"].ToString() + "," + rlm + ";";
                                    //}
                                }
                                #endregion
                            }
                        }
                        #endregion

                        #region 公式
                        sql = "select * from T_sheet_ZsheetPara where 报表名称='" + repName + "'  and 班组=0  and 机组 =" + unit + " and 参数类型='公式' and 公式级别=" + gsjb;

                        DataTable dtMon = null;

                        if (rlDBType == "SQL")
                            dtMon = DBsql.RunDataTable(sql, out errMsg);
                        else
                            dtMon = DBdb2.RunDataTable(sql, out errMsg);

                        if (dtMon != null && dtMon.Rows.Count > 0)
                        {
                            for (int i = 0; i < dtMon.Rows.Count; i++)
                            {
                                //小数点数
                                num = dtMon.Rows[i]["小数点数"].ToString();
                                //参数顺序
                                id = int.Parse(dtMon.Rows[i]["参数顺序"].ToString());
                                //参数ID
                                ParaID = dtMon.Rows[i]["参数ID"].ToString();

                                string pMon = dtMon.Rows[i]["公式"].ToString();

                                string paras = dtMon.Rows[i]["公式参数"].ToString();

                                string month = pm.retMonByValPara(htGY, htUn, paras, pMon);

                                if (month != "")
                                {
                                    res = "";
                                    try
                                    { res = StrHelper.Cale(month); }
                                    catch
                                    {
                                        res = "0";
                                        LogHelper.WriteLog(LogHelper.EnLogType.Run, DateTime.Now.ToString("yyyy-MM-dd H:mm:ss") + " 日值 公式 报程序异常: " + pMon + ":" + paras + ":" + month);
                                    }

                                    if (id != 0)
                                    {
                                        zb[id] = dtMon.Rows[i]["参数名"].ToString();
                                        un[id] = dtMon.Rows[i]["单位"].ToString();
                                        lay[id] = dtMon.Rows[i]["设计值"].ToString();

                                        dv[id] += sh.ShowPoint(res, num) + ',';
                                        dvExcel[id] += res + ',';
                                    }

                                    if (ParaID != "")
                                    {
                                        if (htUn.ContainsKey(ParaID))
                                        {
                                            htUn.Remove(ParaID);
                                            htUn.Add(ParaID, res);
                                        }
                                        else
                                            htUn.Add(ParaID, res);
                                    }
                                }
                            }
                        }

                        #endregion
                    }

                    LogHelper.WriteLog(LogHelper.EnLogType.Run, DateTime.Now.ToString("yyyy-MM-dd H:mm:ss") + "---" + repName + "----" + repType + "----全厂数据横向取值结束!");
                }
                #endregion
            }

            #region 调试模式
            if (TSMS == "yes")
            {
                ArrayList listGy = new ArrayList(htGY.Keys);
                ArrayList listUn = new ArrayList(htUn.Keys);

                listGy.Sort();
                listUn.Sort();

                LogHelper.WriteLog(LogHelper.EnLogType.Run, DateTime.Now.ToString("yyyy-MM-dd H:mm:ss") + "---" + repName + "----" + repType + "----启动调试模式----");

                foreach (string skey in listGy)
                { LogHelper.WriteLog(LogHelper.EnLogType.Run, DateTime.Now.ToString("yyyy-MM-dd H:mm:ss") + "---" + repName + "----" + repType + "----" + skey + "---" + htGY[skey]); }

                foreach (string skey in listUn)
                { LogHelper.WriteLog(LogHelper.EnLogType.Run, DateTime.Now.ToString("yyyy-MM-dd H:mm:ss") + "---" + repName + "----" + repType + "----" + skey + "---" + htUn[skey]); }

                LogHelper.WriteLog(LogHelper.EnLogType.Run, DateTime.Now.ToString("yyyy-MM-dd H:mm:ss") + "---" + repName + "----" + repType + "----关闭调试模式----");
            }
            #endregion

            list.Add(zb);
            list.Add(un);
            list.Add(lay);
            list.Add(dv);
            list.Add(dvExcel);

            return list;

        }

    }

}